aboutsummaryrefslogtreecommitdiff
path: root/src/workspace/git/test_support.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-30 23:58:15 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-30 23:58:34 +0300
commitfc4e1bbf6b0fa2ec37445a5b72356514c7c6be6a (patch)
tree93af04af44a4dcc062a7886c51d70641c1903144 /src/workspace/git/test_support.rs
parentd477341e6af816ff4396042b084a0378ef437b4a (diff)
perf: reduce sidebar git polling overhead
refs #353
Diffstat (limited to 'src/workspace/git/test_support.rs')
-rw-r--r--src/workspace/git/test_support.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/workspace/git/test_support.rs b/src/workspace/git/test_support.rs
new file mode 100644
index 00000000..feba4b3a
--- /dev/null
+++ b/src/workspace/git/test_support.rs
@@ -0,0 +1,51 @@
+use std::path::{Path, PathBuf};
+use std::time::{SystemTime, UNIX_EPOCH};
+
+pub(super) fn temp_test_dir(name: &str) -> PathBuf {
+ let unique = format!(
+ "herdr-workspace-tests-{}-{}-{}",
+ name,
+ std::process::id(),
+ SystemTime::now()
+ .duration_since(UNIX_EPOCH)
+ .unwrap()
+ .as_nanos()
+ );
+ let path = std::env::temp_dir().join(unique);
+ std::fs::create_dir_all(&path).unwrap();
+ path
+}
+
+pub(super) fn write_fake_tracked_repo(root: &Path) {
+ let head_oid = "1111111111111111111111111111111111111111";
+ let upstream_oid = "2222222222222222222222222222222222222222";
+ std::fs::create_dir_all(root.join(".git/refs/heads")).unwrap();
+ std::fs::create_dir_all(root.join(".git/refs/remotes/origin")).unwrap();
+ std::fs::write(root.join(".git/HEAD"), "ref: refs/heads/main\n").unwrap();
+ std::fs::write(root.join(".git/refs/heads/main"), format!("{head_oid}\n")).unwrap();
+ std::fs::write(
+ root.join(".git/refs/remotes/origin/main"),
+ format!("{upstream_oid}\n"),
+ )
+ .unwrap();
+ std::fs::write(
+ root.join(".git/config"),
+ "[branch \"main\"]\n\tremote = origin\n\tmerge = refs/heads/main\n",
+ )
+ .unwrap();
+}
+
+pub(super) fn run_git(cwd: &Path, args: &[&str]) {
+ let output = std::process::Command::new("git")
+ .arg("-C")
+ .arg(cwd)
+ .args(args)
+ .output()
+ .unwrap();
+ assert!(
+ output.status.success(),
+ "git {:?} failed: {}",
+ args,
+ String::from_utf8_lossy(&output.stderr)
+ );
+}