Skip to content

Commit eb9b77f

Browse files
committed
test: fix flaky git tests
1 parent b93c8e3 commit eb9b77f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/testing.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
use std::{fs::OpenOptions, io::Write, process::Command};
1+
use std::{fs::OpenOptions, io::Write, process::Command, sync::Mutex};
22

33
use crate::get_version_control;
44

55
use anyhow::Result;
6+
use once_cell::sync::Lazy;
67
use tempfile::TempDir;
78

9+
// Global mutex to prevent race conditions when changing current directory
10+
// This is the same pattern used in Sapling tests
11+
static GIT_GLOBAL_MUTEX: Lazy<Mutex<()>> = Lazy::new(Mutex::default);
12+
813
pub struct GitCheckout {
914
root: TempDir,
1015
}
@@ -81,6 +86,7 @@ impl GitCheckout {
8186
}
8287

8388
pub fn changed_files(&self, relative_to: Option<&str>) -> Result<Vec<String>> {
89+
let _shared = GIT_GLOBAL_MUTEX.lock().unwrap();
8490
std::env::set_current_dir(self.root())?;
8591
let repo = get_version_control()?;
8692
let files = repo.get_changed_files(relative_to)?;
@@ -92,6 +98,7 @@ impl GitCheckout {
9298
}
9399

94100
pub fn merge_base_with(&self, merge_base_with: &str) -> Result<String> {
101+
let _shared = GIT_GLOBAL_MUTEX.lock().unwrap();
95102
std::env::set_current_dir(self.root())?;
96103
let repo = get_version_control()?;
97104
repo.get_merge_base_with(merge_base_with)

0 commit comments

Comments
 (0)