summaryrefslogtreecommitdiff
path: root/tests/cli_test_utils/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cli_test_utils/git.rs')
-rw-r--r--tests/cli_test_utils/git.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/cli_test_utils/git.rs b/tests/cli_test_utils/git.rs
index d3f35c4..150af45 100644
--- a/tests/cli_test_utils/git.rs
+++ b/tests/cli_test_utils/git.rs
@@ -1,5 +1,50 @@
+use crate::context::TestContext;
+use anyhow::Result;
use assert_cmd::Command;
-use std::path::Path;
+use std::{
+ fs,
+ path::{Path, PathBuf},
+};
+
+pub fn create_clone(c: &TestContext, repo_dir: &Path, relative_name: &str) -> PathBuf {
+ Command::new("git")
+ .arg("clone")
+ .arg(repo_dir)
+ .arg(relative_name)
+ .current_dir(&c.workdir)
+ .timeout(std::time::Duration::from_secs(3))
+ .assert()
+ .success();
+ c.workdir.as_ref().join(relative_name)
+}
+
+pub fn create_commit(repo_dir: &Path) -> Result<String> {
+ let test_file_name = repo_dir.join("some_file");
+ fs::write(test_file_name, "Some content or something")?;
+ Command::new("git")
+ .args(["add", "--all"])
+ .current_dir(&repo_dir)
+ .timeout(std::time::Duration::from_secs(3))
+ .assert()
+ .success();
+ Command::new("git")
+ .args(["commit", "-m", "A commit message"])
+ .current_dir(&repo_dir)
+ .timeout(std::time::Duration::from_secs(3))
+ .assert()
+ .success();
+
+ let commit_hash = String::from_utf8(
+ Command::new("git")
+ .args(["rev-parse", "HEAD"])
+ .current_dir(&repo_dir)
+ .timeout(std::time::Duration::from_secs(3))
+ .output()?
+ .stdout,
+ )?;
+
+ Ok(commit_hash)
+}
pub fn verify_repo_exists(repo_dir: &Path) {
Command::new("git")