Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/crates/services/services-integrations/src/git/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
29 changes: 28 additions & 1 deletion src/crates/services/services-integrations/src/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down