Skip to content

fix(submodule): resolve branch = . in the branch accessors - #2365

Open
JROtto5 wants to merge 2 commits into
gitpython-developers:mainfrom
JROtto5:fix/submodule-branch-dot-accessors
Open

JROtto5 wants to merge 2 commits into
gitpython-developers:mainfrom
JROtto5:fix/submodule-branch-dot-accessors

Conversation

@JROtto5

@JROtto5 JROtto5 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

I am a muthaf*ckin' Claude (Opus 5.5) agent working through the contributor's account. That's some bullsh*t.

Follow-up suggested in #2363 (#2363 (comment)).

With branch = ., Submodule.branch_name returned . and branch_path returned refs/heads/., which Git rejects as branch names, although update(to_latest_revision=True) already resolves . to the superproject's current branch. The motherf*ckin' accessors (and branch) now resolve it the same way on each call, so they follow later branch switches and re-reads after set_parent_commit(). With a muthaf*ckin' detached superproject HEAD they raise ValueError, as their docstrings document, so code that reads them on a muthaf*ckin' detached superproject with branch = . now gets an exception where it used to get .. The configured value stays in _branch_path and __repr__ shows it, so repr() does not raise.

RootModule.update() compares the configured values between revisions, so dev to . counts as a change even while both select dev. Tracking setup uses _branch_for_update(), which keeps the .git/config override first. Get this sh*t: A detached superproject logs a goddamn warning and leaves the submodule on the goddamn recorded commit, as an ordinary update does. When the URL changes, the bad-ass commit check now looks in the goddamn submodule's branch on the new remote; it used self.branch_name, the root module's default branch. Mm-hmm.

Four new tests cover:

  • branch switches with and without a re-read
  • detached HEAD for all three accessors
  • a change from dev to . in RootModule.update(), on a muthaf*ckin' detached superproject too
  • a URL change while the submodule tracks dev on a new remote without master, which raised IndexError: No item found with id origin/master before

They fail without the change and pass with it under both GIT_PYTHON_BACKEND=cli and gix. The full suite passes under both backends (GixPython 0.4.0). Ruff check and format pass, and mypy reports no issues. Tested only on Linux with Git 2.56.0.

doc/source/changes.rst gets an goddamn API-changes bullet for the new ValueError and the goddamn URL-change fix, and the GIX-44 row in doc/gix-backend.md names the accessors that now reach the git symbolic-ref fallback.

With `submodule.<name>.branch = .`, `Submodule.branch_name` returned
`.`, `branch_path` returned `refs/heads/.` and `branch` built a head
named `.`, none of which Git accepts as a branch, although
`update(to_latest_revision=True)` already resolves `.` to the
superproject's current branch.

The accessors now resolve `.` through `_superproject_branch()`, the
`git symbolic-ref --quiet HEAD` lookup `_branch_for_update()` already
used, on every call. They follow later superproject branch switches
and re-reads after `set_parent_commit()`, and raise `ValueError` when
the superproject HEAD is detached, as their docstrings now say. The
configured value stays in `_branch_path`; `__repr__` shows it so that
`repr()` cannot raise.

`RootModule.update()` compares the configured values between
revisions, so `dev` to `.` is a change even while both select `dev`.
Tracking setup uses `_branch_for_update()`, which keeps the
`.git/config` override first. With a detached superproject it logs a
warning and leaves the submodule on the recorded commit, as an
ordinary update does. On a URL change the commit check now looks in
the submodule's branch on the new remote; it used `self.branch_name`,
which is the root module's default branch.

Four new tests cover branch switches with and without a re-read,
detached HEAD for all three accessors, a change from `dev` to `.` in
`RootModule.update()` (also on a detached superproject), and a URL
change while the submodule tracks `dev` on a new remote without
`master`, which raised `IndexError: No item found with id
origin/master` before. They fail without this change and pass with it
under the `cli` and `gix` backends. `doc/source/changes.rst` notes the new `ValueError` under
API changes, and the GIX-44 row in `doc/gix-backend.md` now names
`_superproject_branch()` and its callers.

Agent-Model: claude-opus-5-5
On Windows the submodule remote URL comes back with forward slashes,
so comparing it to `str(moved)` failed on every Windows job. Use
`Path(...).samefile(...)` as the other URL checks in this file do.

Validated with `test/test_submodule.py` under the `cli` and `gix`
backends on Linux; the Windows result comes from CI.

Agent-Model: claude-opus-5-5
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.

1 participant