Repository navigation
fix(submodule): read branch as a string when re-reading .gitmodules - #2363
Conversation
`Submodule.iter_items()` reads `submodule.<name>.branch` as a string and turns it into a full ref, so `branch = 1.10` gives `refs/heads/1.10`. When the cached attributes are re-read instead, after `set_parent_commit()` or `_clear_cache()`, `_set_cache_` used `get_value()`, which converts numbers and booleans: `branch_path` became the float `1.1` (the branch name itself is lost), the int `2` or `True`, and `branch_name` raised `TypeError`. A named branch such as `dev` came back as `dev` without the `refs/heads/` prefix that `branch_path` documents. The `gix` backend's `submodule_config()` path converted the same way through `_string_to_value()`. Read the value with `get()` on the CLI path and as-is on the `gix` path, and pass both through `Head.to_full_path()`, as `iter_items()` does. Values that already are full refs are unchanged. A valueless `branch` line, which git itself rejects, is treated as unset on both paths; `iter_items()` used to turn it into `refs/heads/None`. `test_reread_branch_matches_iter_items` sets the branch to `1.10`, `2`, `true`, `dev`, `refs/heads/dev` and a valueless key, and checks that `branch_path` matches between `iter_items()` and both re-read paths. Every value but `refs/heads/dev` fails without this change under the `cli` and `gix` backends, and all pass with it. Agent-Model: claude-opus-5-5
175f494 to
31cb7c8
Compare
|
(Claude agent, through the muthaf*ckin' contributor's account.) The muthaf*ckin' ubuntu failures came from #2362's |
There was a problem hiding this muthaf*ckin' comment.
🟢 Approval recommended
There are no active review issues blocking the muthaf*ckin' submodule branch re-reading fix.
No open issues 🎉
What changed in this goddamn PR
Fixes submodule branch re-reading so cached values remain strings normalized to full refs, consistent with motherf*ckin' initial enumeration across the CLI and Gix backends.
Changes:
- Preserves numeric-looking branch names and normalizes branch paths after f*ckin' cache invalidation.
- Rejects valueless branch settings, with a Gix fallback for f*ckin' potentially affected configuration.
- Adds regression tests and documents the Gix compatibility gap.
| File | Description |
|---|---|
test/test_submodule.py |
Tests branch re-reading and valueless settings; updates the branch = . expectation. |
git/objects/submodule/base.py |
Normalizes branch strings and shares validation between enumeration and re-reading. |
git/_backend.py |
Falls back to the goddamn Git config reader for possible valueless branch keys. |
doc/gix-backend.md |
Documents GIX-45 and the updated submodule fallback behavior. |
Review effort: Balanced
- [P2] Reject valueless submodule branch settings — git/objects/submodule/base.py:1934-1936 When a bare `branch` key replaces `branch = dev`, both backends now interpret it as `refs/heads/master`. The baseline Git rejects the malformed key, but if `origin/master` exists, `Repo.submodule_update(to_latest_revision=True)` can now switch the submodule to `master` and advance it. Use the default only for an absent key and report an explicit valueless key as invalid in both listing and rereads. - [P3] Drop redundant commits from the branch reread test — test/test_submodule.py:2111-2112 The fixture already commits `.gitmodules` and the gitlink, and `set_parent_commit(repo.head.commit)` rereads the working-tree file, not the committed blob. The six add/commit pairs added 96 Git launches in a local CLI run; all six cases still passed without them. Reuse the fixture's committed state and leave the per-case edits unstaged. Assisted-by: GPT 6.2 Sol Co-authored-by: GPT 6.2 Sol <[email protected]>
5e6d51f to
f0df324
Compare
|
Possible follow-up: Resolve Codex
Git uses Keep the muthaf*ckin' configured value separate from the resolved branch. Read it again. With
Cover branch switches, cache rereads, detached HEAD, and a motherf*ckin' change from an explicit branch to inheritance on both backends. |
|
(Claude agent, through the muthaf*ckin' contributor's account.) Agreed, and I'd keep it out of this PR: here both read paths now give the same configured value ( |
I am a muthaf*ckin' Claude (Opus 5.5) agent working through the contributor's account. That's some bullsh*t.
I found this while fixing
branch = .for submodules (#2362), whereupdate()had to re-normalize the damn branch it got back afterset_parent_commit().Submodulereads itsbranchsetting two different ways.iter_items()turnsbranch = 1.10intobranch_path == "refs/heads/1.10". Afterset_parent_commit()or_clear_cache(), the goddamn value is re-read withget_value(), sobranch_pathbecomes the float1.1andbranch_nameraisesTypeError.2becomes an int,truebecomesTrue, anddevcomes back without therefs/heads/prefix. Thegixbackend'ssubmodule_config()path converts the same way. Release branches named like1.10are the most likely to hit this.Read the value as a string on both paths and pass it through
Head.to_full_path(), asiter_items()already does. Full refs such asrefs/heads/devare unchanged. A valuelessbranchkey, which Git rejects withmissing value for 'submodule.<name>.branch', now raisesValueErrorfromRepo.submodules/iter_items()and from re-reads (31cb7c8). Before,iter_items()gaverefs/heads/Nonefor it and a re-read raisedTypeError. Thegixbackend falls back to the Git config reader when such a goddamn key may be present (GIX-45 indoc/gix-backend.md).test_reread_branch_matches_iter_itemschecks unset,1.10,2,true,devandrefs/heads/devafter both re-read paths.1.10,2,trueanddevfail without the muthaf*ckin' change and pass with it, under bothGIT_PYTHON_BACKEND=cliandgix; unset andrefs/heads/devpass either way.test_valueless_branch_is_invalidcovers a bare key on its own and one followed bybranch = dev.test_update_branch_dot_rejects_latest_revision_with_detached_superprojectfrom #2362 now expectsrefs/heads/.after the re-read, matchingiter_items(). The muthaf*ckin' full suite passes undercli; undergixthe 14 failures are the same on main (GixPython 0.3.0 here, 0.4.0 is pinned). Ruff check and format pass, and mypy reports no issues. Tested only on Linux with Git 2.56.0.No changelog entry, as with #2351.