Clarify detached HEAD access and isolate test branch state by Byron · Pull Request #2231 · gitpython-developers/GitPython
Repository navigation
Clarify detached HEAD access and isolate test branch state - #2231
Merged
Byron merged 1 commit into main from detached-head Sep 10, 2026
Merged
Clarify detached HEAD access and isolate test branch state #2231 Byron merged 1 commit into main from detached-head
Conversation
Byron commented Sep 9, 2026 · edited Loading
Copy link Copy Markdown
Member
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
- refackiew
Everything below this line was generated by Codex GPT-6.
Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Detached HEAD makes repo.head.reference raise TypeError, but its public documentation and diagnostic did not explain how to obtain the commit. The diagnostic now points to .commit and .object, and the property documentation and tutorial show repo.head.commit.hexsha for both HEAD states. They also explain why assigning a commit to .reference succeeds while reading it afterward raises. Return types and exception types are preserved; the existing diagnostic gains a hint.
The test suite now supplies branch state in its temporary repositories, gives writable remote fixtures their own master, and uses explicit refspecs where an upstream is unnecessary. Branch-dependent assertions use writable fixtures, and the reflog assertion compares against Git instead of assuming consecutive entries name different commits. A regression covers bare and working clones of a detached commit that no branch points to. The Ubuntu/Python 3.14 CI job additionally runs the suite from detached and non-master source checkouts, with master absent in the latter.
Refs #2230 .
Validation:
- Python 3.14.7: full suite using
GIT_PYTHON_TEST_GIT_REPO_BASEwith non-master and detached source clones, each without a localmaster: 760 passed, 81 skipped, 1 xfailed , plus 14 passing subtests per state. Six tests needing network or process access were run separately and passed in both states. - The extended API regression failed on the missing diagnostic hint before the implementation changed.
- Repository-wide Ruff lint and formatting checks passed.
- Sphinx HTML build passed. Its 12 Python 3.14 annotation warnings exactly match the unchanged baseline.
Git reference: git/git at 1630431f326e15fcde608827b5ff38422528eb59, Documentation/git-symbolic-ref.adoc. Apple Git 2.50.1 confirms that git symbolic-ref -q HEAD exits 1 for detached HEAD while git rev-parse HEAD returns the commit ID.
Clarify detached HEAD access and attach writable test fixtures (#2230)
6bcb25b
<!-- agent --> Reading head.reference or active_branch raises TypeError when HEAD points directly to a commit, but the public documentation did not clearly explain how to access that commit. Document head.commit.hexsha for attached and detached HEADs, explain the reference setter/getter asymmetry, and clarify that active_branch requires an attached HEAD. Preserve the exception type and existing message prefix while adding a hint to use .commit or .object. Writable test fixtures assumed cloning produced an attached HEAD, so their branch access could fail when the source checkout was detached. Have with_rw_repo create and attach master at the requested revision when its clone is detached, retaining the clone's branch and tracking configuration otherwise. Explicitly attach the temporary bare remote to its own master branch before cloning it for remote tests. Assisted-by: GPT 6.0 Co-authored-by: GPT 6.0 <codex@openai.com>Byron force-pushed the detached-head branch from
fb9fe55 to
6bcb25b
Compare
September 10, 2026 03:17 Byron marked this pull request as ready for review September 10, 2026 03:19 Copilot PR reviewer Copilot
AI
lite review requested due to automatic review settings September 10, 2026 03:19 Copilot started reviewing on behalf of Byron September 10, 2026 03:22
View session
Copilot PR reviewer Copilot
AI
reviewed Sep 10, 2026
View reviewed changes
Copilot
AI
left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
🔵 Needs a closer look
Normalize annotated-tag revisions to commits before creating the fixture branch.
Pull request overviewThis pull request clarifies detached-HEAD access and isolates test fixtures from source branch state.
Changes:
- Documents detached-HEAD commit and reference behavior.
- Improves detached-reference diagnostics.
- Stabilizes temporary repository branch setup.
| File | Summary |
|---|---|
test/lib/helper.py |
Adjusts writable fixture branch setup; annotated-tag revisions need normalization to a commit. |
git/repo/base.py |
Clarifies detached active_branch behavior. |
git/refs/symbolic.py |
Documents reference semantics and improves diagnostics. |
doc/source/tutorial.rst |
Adds detached-HEAD usage guidance. |
Suppressed comments (1)
test/lib/helper.py:165
create_headresolves a string withrev_parse, so an annotated tag resolves to aTagObjectandHeadrejects it as non-commit. The attached-HEAD branch above avoids this by callingrw_repo.commit(working_tree_ref), so detached-source fixtures regress for any annotated-tagworking_tree_ref; normalize the revision to a commit before creatingmaster.
rw_repo.head.reference = rw_repo.create_head(
"master", working_tree_ref, force=True, logmsg="Create test branch"
)
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
4905b4a
into
main
Sep 10, 2026
54 checks passed
Byron
deleted the
detached-head
branch
October 5, 2026 03:23
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment