fix: validate checkout positional reference options · gitpython-developers/GitPython@8da6508 · GitHub
Skip to content

Commit 8da6508

Browse files
Byroncodex
andcommitted
fix: validate checkout positional reference options
<!-- agent --> Head.checkout checked keyword options but omitted the serialized reference from its existing unsafe-option validation (GHSA-23mf-xhv8-69c2). Reference names can originate in a cloned repository, so callers could reach behavior that normally requires explicit opt-in without supplying any checkout options themselves. Pass self through the shared option-candidate helper, matching the argument actually sent to Git. This applies the existing policy to direct and cloned references, including abbreviated option spellings, while retaining allow_unsafe_options=True and ordinary checkout semantics. A leading -- separator would instead make the reference a pathspec and break branch switching. Add direct-reference regression coverage and a local clone regression using synthetic file content; the latter also verifies explicit opt-in. Both regression tests failed before the guard change. All 30 tests in test/test_refs.py pass with Python 3.12.14 and Apple Git 2.50.1; git diff --check passes. Git behavior reference: local git/git checkout at 1630431f326e15fcde608827b5ff38422528eb59, builtin/checkout.c checkout_main pathspec_from_file handling, which parses file contents as pathspecs. No Git source was copied. Assisted-by: GPT 6.0 Co-authored-by: GPT 6.0 <codex@openai.com>
1 parent fb7e089 commit 8da6508

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

doc/source/changes.rst

Lines changed: 1 addition & 0 deletions

git/refs/head.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def checkout(
283283
"""
284284
if not allow_unsafe_options:
285285
Git.check_unsafe_options(
286-
options=Git._option_candidates([], kwargs),
286+
options=Git._option_candidates([self], kwargs),
287287
unsafe_options=Git.unsafe_git_pathspec_from_file_options,
288288
)
289289
kwargs["f"] = force

test/test_refs.py

Lines changed: 19 additions & 0 deletions

0 commit comments

Comments
 (0)