properly handle detachted git worktrees #5097
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now we check if
.git
exists and is a directory to detect a git repo root.This does not work well for git repos with multiple/detached work-tree where
.git
is a file which contains the location of the folder that contains files that would normally be located in
.git
.This PR changes all checks for
.git
to use.exists()
instead of.is_dir()
, so it also works for files.Since the
git
cli uses the same detection mechanism (trytough .git && git status
in an empty directory)this seems more inline with the intended behavior.
Furthermore, workflows with multiple worktrees become much nicer with this (I use one for each branch to quickly context switch)
as the file picker now stops at the correct location.
Fixing this will also be important for getting repo caching to work correctly in the future.
This change is technically a breaking for repos that contain random
.git
files but as this messes withthe
git
cli as well, so I think those cases can be ignored and I did not mark it as a breaking change.