fix(submodule): resolve `branch = .` when update() clones a submodule by JROtto5 · Pull Request #2362 · gitpython-developers/GitPython
Repository navigation
fix(submodule): resolve branch = . when update() clones a submodule - #2362
Merged
Byron merged 5 commits into gitpython-developers:main from JROtto5:fix/submodule-branch-dot Nov 24, 2026
Merged
fix(submodule): resolve branch = . when update() clones a submodule #2362
Byron merged 5 commits into
gitpython-developers:main from
JROtto5:fix/submodule-branch-dot
Conversation
JROtto5 commented Nov 24, 2026
Copy link Copy Markdown
Contributor
I am a Claude (Opus 5.5) agent working through the contributor's account.
I have been checking GitPython against what Git itself does (as in #2351 , #2353 and #2357 ), this time for submodules. gitmodules(5) says submodule.<name>.branch = . means "the same name as the superproject's current branch". With the superproject on dev, git submodule update --init --remote checks out the submodule's dev tip, but sm.update(to_latest_revision=True) on a fresh clone ends up on the submodule's default branch.
When update() clones the module, it looks for a remote branch literally named .. Through repo.submodules this logs "Failed to checkout tracking branch refs/heads/." and stays on whatever the clone checked out. After set_parent_commit() the value is re-read without the refs/heads/ prefix, and branch_name raises ValueError for a named branch like dev as well as for ..
Normalize the branch to a full ref and resolve refs/heads/. to the superproject's active branch before the lookup. A detached superproject keeps the old warning, because git refuses in that case.
Only the initial clone in Submodule.update() resolves .. RootModule.update (when the configured branch changes) and Submodule.branch still take it literally and are left alone here.
Validation on Linux, Git 2.56.0:
test_update_to_latest_revision_follows_superproject_branch(newbranch-dotfixture, both paths) andtest_update_to_latest_revision_after_reread_follows_named_branchfail without the change and pass with it underGIT_PYTHON_BACKEND=cliandgix.test_update_branch_dot_with_detached_superproject_warnspins the unchanged detached case. The full test suite passes under both backends.git submodule update --init --remoteon the same fixture checks out thedevtip.- Ruff check and format pass; mypy reports no issues.
Not run on other platforms.
JROtto5 and others added 5 commits November 24, 2026 18:54
fix(submodule): resolve branch = . when update() clones a submodule
1dfe4e2
gitmodules(5) defines `submodule.<name>.branch = .` as "the same name as the superproject's current branch". With the superproject on `dev`, `git submodule update --init --remote` checks out the submodule's `dev` tip. When update() cloned such a submodule it looked for a remote branch literally named `.` and never found it: from `repo.submodules` it logged "Failed to checkout tracking branch refs/heads/." and stayed on the remote's default branch, so `to_latest_revision=True` moved the submodule to the wrong tip; after `set_parent_commit()` the branch is re-read without the refs/heads/ prefix and `branch_name` raised ValueError instead, for a named branch such as `dev` as well as `.`. Normalize the configured branch to a full ref first, then resolve `refs/heads/.` to the superproject's active branch before the remote-branch lookup. A detached superproject keeps the previous behaviour (the lookup fails and the warning is logged); git refuses in that case. Already-cloned submodules are not touched: update() follows their existing tracking branch, as before. The new `branch-dot` fixture puts the superproject clone on `dev`. `test_update_to_latest_revision_follows_superproject_branch` covers the `repo.submodules` path and the re-read path, and `test_update_to_latest_revision_after_reread_follows_named_branch` the re-read of `dev`; both fail without this change under the `cli` and `gix` backends and pass with it. A third test pins the detached case. Agent-Model: claude-opus-5-5
fix(submodule): follow the current superproject branch on update
a03950f
When a submodule with `branch = .` was cloned on `dev`, subsequent `update(to_latest_revision=True)` calls kept using `origin/dev` after the superproject switched to `master`. The branch selection only resolved `.` during cloning. Resolve the remote-tracking ref from the current superproject branch when selecting the latest revision. If the selected ref differs from the submodule's upstream, check out its commit detached to preserve the local branch. The regression switches the superproject from `dev` to `master`, fetches a newer `master` commit, and switches back using cached refs. It failed before the fix and passes with the CLI and Gix backends. Git's `submodule update --remote` selects the same commits. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
fix(submodule): honor branch overrides in superproject config
c327590
When `.gitmodules` sets `branch = .`, Git takes an explicit `submodule.<name>.branch` setting from the superproject configuration before inheriting the current branch. GitPython inherited `dev` even when the superproject explicitly selected `master`. Share the branch lookup between cloning and latest-revision selection. Read the override for each update so an initialized submodule can follow changes to that setting, including a switch back to `.`. A target on another upstream is checked out detached to preserve the local branch. Use the existing Gix scalar config adapter for text keys. Fall back to Git for non-UTF-8 keys, which GixPython 0.3.0 cannot accept, and record the limitation in `doc/gix-backend.md`. The override regression failed on both backends before the fix. It now passes on both and selects the same commits as `git submodule update --remote` across the override changes. The byte-key config regression also passes on both backends. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
fix(submodule): reject inherited latest updates with detached HEAD
6caf1e1
A latest-revision update with `branch = .` could fall back to the submodule's tracking branch when the superproject's `HEAD` was detached. After `set_parent_commit()` reread the raw branch setting, normalization turned the old error into a warning and the checkout could advance to the remote's default tip. Resolve the effective branch before cloning or fetching. Raise `ValueError` for an unresolved inherited branch, as the Git CLI also rejects this update. Explicit branch overrides still work, and an ordinary update checks out the recorded gitlink commit. The regression covers the reread, both initialized and uninitialized submodules, and the recorded-commit update. Git 2.54.0 rejects the same `submodule update --init --remote` request. All 24 targeted tests passed on each of the CLI and Gix backends. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: high
fix(submodule): follow symbolic HEAD aliases for branch inheritance
01abf35
When `HEAD` points to `refs/heads/dev` and that ref aliases `refs/heads/master`, `branch = .` selected `origin/dev` through the immediate HEAD target. Git follows the chain and selects `origin/master`. Use recursive `git symbolic-ref` to select the final branch during initialization and latest-revision updates. GixPython 0.3.0's `head_name()` and `head_ref()` stop at the first target, while `follow_to_object()` cannot return an unborn terminal ref. Keep the recursive HEAD lookup on the CLI path and record the gap as GIX-44. The alias regression failed on both backends before the fix. It now matches Git 2.54.0 on initialization and follows a later remote commit. The targeted run passed 25 tests on CLI and 27 on Gix, including two native-only checks. Agent-Model: gpt-6.2-sol Agent-Reasoning-Effort: highByron force-pushed the fix/submodule-branch-dot branch from
e47145c to
01abf35
Compare
November 24, 2026 17:56 JROtto5 mentioned this pull request Nov 24, 2026 fix(submodule): read
branch as a string when re-reading .gitmodules
#2363
Merged
Byron
merged commit 1003977
into
gitpython-developers : main
Nov 24, 2026
61 of 64 checks passed
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment