Add some logging to debug missing parent git repositories (#25943)

We've had some issues reported with git repositories not getting
detected when they're a strict parent of the worktree root. Add a bit
more logging to understand what's going on here.

Release Notes:

- N/A
This commit is contained in:
Cole Miller 2025-03-03 13:39:04 -05:00 committed by GitHub
parent 16ab8701a2
commit b774a4b8d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4304,6 +4304,7 @@ impl BackgroundScanner {
} }
let ancestor_dot_git = ancestor.join(*DOT_GIT); let ancestor_dot_git = ancestor.join(*DOT_GIT);
log::debug!("considering ancestor: {ancestor_dot_git:?}");
// Check whether the directory or file called `.git` exists (in the // Check whether the directory or file called `.git` exists (in the
// case of worktrees it's a file.) // case of worktrees it's a file.)
if self if self
@ -4312,21 +4313,26 @@ impl BackgroundScanner {
.await .await
.is_ok_and(|metadata| metadata.is_some()) .is_ok_and(|metadata| metadata.is_some())
{ {
log::debug!(".git path exists");
if index != 0 { if index != 0 {
// We canonicalize, since the FS events use the canonicalized path. // We canonicalize, since the FS events use the canonicalized path.
if let Some(ancestor_dot_git) = if let Some(ancestor_dot_git) =
self.fs.canonicalize(&ancestor_dot_git).await.log_err() self.fs.canonicalize(&ancestor_dot_git).await.log_err()
{ {
let location_in_repo = root_abs_path
.as_path()
.strip_prefix(ancestor)
.unwrap()
.into();
log::debug!(
"inserting parent git repo for this worktree: {location_in_repo:?}"
);
// We associate the external git repo with our root folder and // We associate the external git repo with our root folder and
// also mark where in the git repo the root folder is located. // also mark where in the git repo the root folder is located.
let local_repository = self.state.lock().insert_git_repository_for_path( let local_repository = self.state.lock().insert_git_repository_for_path(
WorkDirectory::AboveProject { WorkDirectory::AboveProject {
absolute_path: ancestor.into(), absolute_path: ancestor.into(),
location_in_repo: root_abs_path location_in_repo,
.as_path()
.strip_prefix(ancestor)
.unwrap()
.into(),
}, },
ancestor_dot_git.clone().into(), ancestor_dot_git.clone().into(),
self.fs.as_ref(), self.fs.as_ref(),
@ -4341,9 +4347,13 @@ impl BackgroundScanner {
// Reached root of git repository. // Reached root of git repository.
break; break;
} else {
log::debug!(".git path doesn't exist");
} }
} }
log::debug!("containing git repository: {containing_git_repository:?}");
let (scan_job_tx, scan_job_rx) = channel::unbounded(); let (scan_job_tx, scan_job_rx) = channel::unbounded();
{ {
let mut state = self.state.lock(); let mut state = self.state.lock();