Fix Repo.active_branch resolution for reftable-backed repositories#2114
Merged
Fix Repo.active_branch resolution for reftable-backed repositories#2114
Repo.active_branch resolution for reftable-backed repositories#2114Conversation
Copilot
AI
changed the title
[WIP] Fix issue with repository fetching in GitPython
Fix Mar 20, 2026
Repo.active_branch resolution for reftable-backed repositories
057fc47 to
0a27f73
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make Repo.active_branch work correctly on repositories using Git’s reftable ref backend (where filesystem-based ref parsing can misidentify the active branch).
Changes:
- Added a guard in
Repo.active_branchthat raisesValueErrorwhen the resolved branch name is.invalid. - Added tests asserting
Repo.active_branchraisesValueErrorwhenHEADpoints atrefs/heads/.invalid(including a reftable init case). - Added a detached-HEAD regression test asserting
Repo.active_branchraisesTypeError.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
git/repo/base.py |
Adds .invalid detection and raises ValueError instead of resolving via git plumbing. |
test/test_repo.py |
Adds tests for .invalid HEAD and detached HEAD behavior (currently expecting exceptions). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0a27f73 to
bbfa27c
Compare
reviewed-by: Sebastian Thiel <sebastian.thiel@icloud.com>
bbfa27c to
77b1135
Compare
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.
GitPython currently infers the active branch from ref files directly, which breaks on repositories using Git’s reftable ref storage and can surface
refs/heads/.invalidas the active branch. This PR switches active-branch resolution to Git’s symbolic-ref plumbing so behavior stays correct across ref backends.Active branch resolution
Repo.active_branch’s direct HEAD reference dereference path withgit symbolic-ref -q HEAD.Headfrom the resolved symbolic ref path returned by Git.TypeErrorbehavior.Regression coverage
repo.active_branch.pathmatchesgit symbolic-ref HEADrepo.active_branch.namematchesgit symbolic-ref --short HEADRepo.active_branchraisesTypeErrorwith the expected detached-reference message.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.