Merge 'Fix git directory resolution in simulator to support worktrees' from Jussi Saurio

sim cannot be run in a git worktree on main

Closes #3794
This commit is contained in:
Pekka Enberg
2025-10-21 16:03:58 +03:00
committed by GitHub

View File

@@ -470,12 +470,18 @@ impl BugBase {
}
fn find_git_dir(start_path: impl AsRef<Path>) -> Option<PathBuf> {
// HACK ignores stuff like bare repo, worktree, etc.
let mut current = start_path.as_ref().to_path_buf();
loop {
let git_path = current.join(".git");
if git_path.is_dir() {
return Some(git_path);
} else if git_path.is_file() {
// Handle git worktrees - .git is a file containing "gitdir: <path>"
if let Ok(contents) = read_to_string(&git_path) {
if let Some(gitdir) = contents.strip_prefix("gitdir: ") {
return Some(PathBuf::from(gitdir));
}
}
}
if !current.pop() {
return None;