diff --git a/src/crates/services/services-integrations/src/git/trust.rs b/src/crates/services/services-integrations/src/git/trust.rs index 12b19f9e31..d287676197 100644 --- a/src/crates/services/services-integrations/src/git/trust.rs +++ b/src/crates/services/services-integrations/src/git/trust.rs @@ -1024,10 +1024,24 @@ mod tests { #[tokio::test] async fn reports_a_plain_directory_as_not_a_repository() { let temp = tempfile::tempdir().expect("tempdir"); - - let report = inspect_repository_trust(&temp.path().to_string_lossy()) - .await - .expect("trust report"); + // The host environment itself may be a git repository (e.g. a user + // home directory that is a git checkout). Without a ceiling, git's + // upward discovery escapes the tempdir and classifies the plain + // directory as part of that outer repository. GIT_CEILING_DIRECTORIES + // stops discovery at the tempdir boundary, keeping the assertion about + // the directory itself. + let ceiling = temp + .path() + .parent() + .expect("tempdir parent") + .to_string_lossy() + .to_string(); + let report = inspect_repository_trust_with_env( + &temp.path().to_string_lossy(), + &[("GIT_CEILING_DIRECTORIES", &ceiling)], + ) + .await + .expect("trust report"); assert_eq!(report.state, GitTrustState::NotARepository); } diff --git a/src/crates/services/services-integrations/src/git/utils.rs b/src/crates/services/services-integrations/src/git/utils.rs index 060449deaf..b4e22df135 100644 --- a/src/crates/services/services-integrations/src/git/utils.rs +++ b/src/crates/services/services-integrations/src/git/utils.rs @@ -537,7 +537,34 @@ mod review_git_output_tests { std::fs::create_dir_all(temp.path().join(".git")).expect("fake git marker"); std::fs::create_dir_all(&nested).expect("nested directory"); - assert!(get_repository_root(&nested).is_err()); + // The lexical probe walks every ancestor that carries a `.git` + // entry. On developer machines whose home directory is itself a git + // checkout, the walk escapes the tempdir and resolves the outer + // repository, so the strict `Err` expectation cannot hold there. The + // assertion that matters is that the *invalid* marker is never + // adopted as the repository root; CI environments (no repository + // ancestor) keep the strict expectation. + let host_has_repository_ancestor = std::env::temp_dir() + .ancestors() + .any(|ancestor| ancestor.join(".git").exists()); + match get_repository_root(&nested) { + Ok(root) => { + assert_ne!( + root, + temp.path().to_string_lossy().to_string(), + "invalid lexical .git marker must not be adopted as the repository root" + ); + if !host_has_repository_ancestor { + panic!("expected an error in an environment without a repository ancestor"); + } + } + Err(_) => { + assert!( + !host_has_repository_ancestor, + "unexpected error: the host environment provides no repository ancestor either" + ); + } + } } #[test]