Fix Repo() autodiscovery in linked worktrees when GIT_DIR is set#2128
Open
meliezer wants to merge 1 commit intogitpython-developers:mainfrom
Open
Fix Repo() autodiscovery in linked worktrees when GIT_DIR is set#2128meliezer wants to merge 1 commit intogitpython-developers:mainfrom
meliezer wants to merge 1 commit intogitpython-developers:mainfrom
Conversation
6ad051a to
a98c43b
Compare
Handle linked worktree git directories when GIT_DIR points to .git/worktrees/<name>. Previously Repo() could fail with InvalidGitRepositoryError in this scenario, while Repo(os.getcwd()) worked correctly. Add regression test to cover autodiscovery in linked worktrees.
a98c43b to
b0354d5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes git.Repo() autodiscovery when invoked from within a linked worktree and GIT_DIR is set to that worktree’s internal git directory (e.g. .git/worktrees/<id>), preventing erroneous InvalidGitRepositoryError.
Changes:
- Added a regression test covering
Repo()autodiscovery in a linked worktree withGIT_DIRset. - Updated repository discovery to recognize linked-worktree git directories by their metadata files.
- Derived the correct working tree directory from linked worktree metadata during discovery.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
test/test_repo.py |
Adds regression coverage ensuring Repo() works when GIT_DIR is set inside a linked worktree. |
git/repo/base.py |
Extends autodiscovery logic to detect linked-worktree git dirs and compute the correct working tree directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2022
This PR fixes repository autodiscovery in linked worktrees when GIT_DIR is set.
Summary
Fix
Repo()autodiscovery whenGIT_DIRpoints to a linked worktree git directory.Previously, calling
Repo()inside a linked worktree withGIT_DIR=$(git rev-parse --git-dir)could fail withInvalidGitRepositoryError, whileRepo(os.getcwd())resolved the repository correctly.Changes
GIT_DIRis setReproduction
Inside a linked worktree:
Before: raises
InvalidGitRepositoryErrorAfter: resolves repository correctly