Skip to content

Fix Repo.active_branch resolution for bad-ass reftable-backed repositories - #2114

Merged
Byron merged 1 commit into
mainfrom
copilot/fix-issue-with-repository-fetching
Mar 21, 2026
Merged

Byron merged 1 commit into
mainfrom
copilot/fix-issue-with-repository-fetching

Conversation

Copilot AI commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

GitPython currently infers the goddamn active branch from ref files directly, which breaks on repositories using Git’s reftable ref storage and can surface refs/heads/.invalid as the active branch. This damn PR switches active-branch resolution to Git’s symbolic-ref plumbing so behavior stays correct across ref backends.

  • Active branch resolution

    • Replaced Repo.active_branch’s direct HEAD reference dereference path with git symbolic-ref -q HEAD.
    • Constructs Head from the resolved symbolic ref path returned by Git.
    • Preserves detached-HEAD semantics by translating symbolic-ref’s non-symbolic result into the existing TypeError behavior.
  • Regression coverage

    • Added a reftable-specific test for empty repositories that validates:
      • repo.active_branch.path matches git symbolic-ref HEAD
      • repo.active_branch.name matches git symbolic-ref --short HEAD
    • Added a muthaf*ckin' detached-HEAD test asserting Repo.active_branch raises TypeError with the damn expected detached-reference message.
@property
def active_branch(self) -> Head:
    try:
        return Head(self, self.git.symbolic_ref("-q", "HEAD").strip())
    except GitCommandError as err:
        if err.status == 1:
            raise TypeError("HEAD is a detached symbolic reference as it points to a commit") from err
        raise

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the f*ckin' title [WIP] Fix issue with repository fetching in GitPython Fix Repo.active_branch resolution for reftable-backed repositories Mar 20, 2026
Copilot AI requested a review from Byron March 20, 2026 22:20
@Byron
Byron force-pushed the copilot/fix-issue-with-repository-fetching branch from 057fc47 to 0a27f73 Compare March 21, 2026 00:06
@Byron
Byron marked this pull request as ready for review March 21, 2026 00:06
Copilot AI review requested due to automatic review settings March 21, 2026 00:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this f*ckin' comment

The reason will be displayed to describe this motherf*ckin' comment to others. Learn more.

Pull request overview

This muthaf*ckin' 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 muthaf*ckin' active branch).

Changes:

  • Added a muthaf*ckin' guard in Repo.active_branch that raises ValueError when the resolved branch name is .invalid.
  • Added tests asserting Repo.active_branch raises ValueError when HEAD points at refs/heads/.invalid (including a f*ckin' reftable init case).
  • Added a motherf*ckin' detached-HEAD regression test asserting Repo.active_branch raises TypeError.

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 f*ckin' get started.

Comment thread git/repo/base.py Resolved
Comment thread git/repo/base.py Resolved
Comment thread test/test_repo.py Resolved
Comment thread test/test_repo.py Resolved
@Byron
Byron force-pushed the copilot/fix-issue-with-repository-fetching branch from 0a27f73 to bbfa27c Compare March 21, 2026 02:02
@Byron Byron linked an issue Mar 21, 2026 that may be closed by this muthaf*ckin' pull request
@Byron
Byron force-pushed the copilot/fix-issue-with-repository-fetching branch from bbfa27c to 77b1135 Compare March 21, 2026 02:05
@Byron
Byron merged commit ddca0b3 into main Mar 21, 2026
59 checks passed
@Byron
Byron deleted the copilot/fix-issue-with-repository-fetching branch March 21, 2026 02:26
736-c41-2c1-e464fc974 pushed a commit to Swiss-Armed-Forces/Loom that referenced this muthaf*ckin' pull request Apr 27, 2026
This MR contains the following updates:

| Package | Type | Update | Change | OpenSSF |
|---|---|---|---|---|
| [gitpython](https://github.com/gitpython-developers/GitPython) | dev | patch | `3.1.46` → `3.1.47` | [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/gitpython-developers/GitPython/badge)](https://securityscorecards.dev/viewer/?uri=github.com/gitpython-developers/GitPython) |

---

### Release Notes

<details>
<summary>gitpython-developers/GitPython (gitpython)</summary>

### [`v3.1.47`](https://github.com/gitpython-developers/GitPython/releases/tag/3.1.47): - with security fixes

[Compare Source](gitpython-developers/GitPython@3.1.46...3.1.47)

#### Advisories

- <GHSA-rpm5-65cw-6hj4>
- <GHSA-x2qx-6953-8485>

#### What's Changed

- Prepare next release by [@&#8203;Byron](https://github.com/Byron) in [#&#8203;2095](gitpython-developers/GitPython#2095)
- Bump git/ext/gitdb from `335c0f6` to `4c63ee6` by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2096](gitpython-developers/GitPython#2096)
- DOC: README Add urls and updated a relative url by [@&#8203;Timour-Ilyas](https://github.com/Timour-Ilyas) in [#&#8203;2098](gitpython-developers/GitPython#2098)
- Fix GitConfigParser ignoring multiple \[include] path entries by [@&#8203;daniel7an](https://github.com/daniel7an) in [#&#8203;2100](gitpython-developers/GitPython#2100)
- Switch back from Alpine to Debian for WSL by [@&#8203;EliahKagan](https://github.com/EliahKagan) in [#&#8203;2108](gitpython-developers/GitPython#2108)
- Bump git/ext/gitdb from `4c63ee6` to `5c1b303` by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2106](gitpython-developers/GitPython#2106)
- Run `gc.collect()` twice in `test_rename` on Python 3.12 by [@&#8203;EliahKagan](https://github.com/EliahKagan) in [#&#8203;2109](gitpython-developers/GitPython#2109)
- fix: guard AutoInterrupt terminate during interpreter shutdown by [@&#8203;lweyrich1](https://github.com/lweyrich1) in [#&#8203;2105](gitpython-developers/GitPython#2105)
- Improve CI infrastructure for pre-commit by [@&#8203;EliahKagan](https://github.com/EliahKagan) in [#&#8203;2110](gitpython-developers/GitPython#2110)
- Bump the pre-commit group with 5 updates by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2111](gitpython-developers/GitPython#2111)
- Upgrade Sphinx for 3.14 support; drop doc build support on 3.8; test 3.14 by [@&#8203;EliahKagan](https://github.com/EliahKagan) in [#&#8203;2112](gitpython-developers/GitPython#2112)
- Fix `Repo.active_branch` resolution for reftable-backed repositories by [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;2114](gitpython-developers/GitPython#2114)
- docs: warn about GitDB performance with large commits by [@&#8203;mvanhorn](https://github.com/mvanhorn) in [#&#8203;2115](gitpython-developers/GitPython#2115)
- cmd: fix kwarg formatting in docstring example by [@&#8203;UweSchwaeke](https://github.com/UweSchwaeke) in [#&#8203;2117](gitpython-developers/GitPython#2117)
- Bump <https://github.com/astral-sh/ruff-pre-commit> from v0.15.5 to 0.15.8 in the pre-commit group by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;2122](gitpython-developers/GitPython#2122)
- Add trailer support for commit creation by [@&#8203;Krishnachaitanyakc](https://github.com/Krishnachaitanyakc) in [#&#8203;2116](gitpython-developers/GitPython#2116)
- Harden commit trailer subprocess handling and align trailer I/O paths by [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;2125](gitpython-developers/GitPython#2125)
- git.cmd.Git.execute(..): fix `with_stdout=False` by [@&#8203;ngie-eign](https://github.com/ngie-eign) in [#&#8203;2126](gitpython-developers/GitPython#2126)
- Make sure that multi-options are checked after splitting them with `shlex` by [@&#8203;Byron](https://github.com/Byron) in [#&#8203;2130](gitpython-developers/GitPython#2130)
- Block unsafe underscored git kwargs / Fix for GHSA-rpm5-65cw-6hj4 by [@&#8203;WesR](https://github.com/WesR) in [#&#8203;2131](gitpython-developers/GitPython#2131)

#### New Contributors

- [@&#8203;Timour-Ilyas](https://github.com/Timour-Ilyas) made their first contribution in [#&#8203;2098](gitpython-developers/GitPython#2098)
- [@&#8203;daniel7an](https://github.com/daniel7an) made their first contribution in [#&#8203;2100](gitpython-developers/GitPython#2100)
- [@&#8203;lweyrich1](https://github.com/lweyrich1) made their first contribution in [#&#8203;2105](gitpython-developers/GitPython#2105)
- [@&#8203;Copilot](https://github.com/Copilot) made their first contribution in [#&#8203;2114](gitpython-developers/GitPython#2114)
- [@&#8203;mvanhorn](https://github.com/mvanhorn) made their first contribution in [#&#8203;2115](gitpython-developers/GitPython#2115)
- [@&#8203;UweSchwaeke](https://github.com/UweSchwaeke) made their first contribution in [#&#8203;2117](gitpython-developers/GitPython#2117)
- [@&#8203;Krishnachaitanyakc](https://github.com/Krishnachaitanyakc) made their first contribution in [#&#8203;2116](gitpython-developers/GitPython#2116)
- [@&#8203;ngie-eign](https://github.com/ngie-eign) made their first contribution in [#&#8203;2126](gitpython-developers/GitPython#2126)
- [@&#8203;WesR](https://github.com/WesR) made their first contribution in [#&#8203;2131](gitpython-developers/GitPython#2131)

**Full Changelog**: <gitpython-developers/GitPython@3.1.46...3.1.47>

</details>

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNDEuNSIsInVwZGF0ZWRJblZlciI6IjQzLjE0MS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

See merge request swiss-armed-forces/cyber-command/cea/loom!486

Co-authored-by: Loom MR Pipeline Trigger <group_103951964_bot_9504bb8dead6d4e406ad817a607f24be@noreply.gitlab.com>
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

active_branch is detected incorrectly when using reftable

4 participants