GitHubJacksonized

fix: preserve positional operands in high-level Git commands by Byron · Pull Request #2247 · gitpython-developers/GitPython

<!-- agent -->
`Remote.pull()` validated keyword options but forwarded refspecs through
`git pull`, whose internal fetch invocation loses the `--` separator.
GHSA-f9j4-qggq-h239 reports the resulting positional validation bypass.

Reject all leading-dash refspecs and remote names before spawning Git,
rather than trying to enumerate dangerous option spellings. This also
applies with `allow_unsafe_options=True`: explicit options still belong in
keyword arguments. Document the behavior and add an unreleased changelog
entry. No shell quoting change is needed; the problem is Git's own option
parsing, not splitting arguments in Python.

Git reference: `builtin/pull.c:run_fetch()` at Git commit
`12cb6293d6288865c1a133cf22accbaf99d13eb6` forwards the remote and refspecs
without an option terminator. Tested with Apple Git 2.54.0.

Assisted-by: GPT 6.0
Co-authored-by: GPT 6.0 <[email protected]>
<!-- agent -->
A leading-dash name could change the operation requested by a high-level
API. In particular, `delete_head("--force", branch, force=False)` deleted
an unmerged branch, and renaming a `Head` named `--force` renamed the
current branch instead of rejecting the missing source.

Terminate options before names in branch deletion and rename, remote
reference deletion, and tag creation and deletion. Keep explicit keyword
options and the existing unsafe-option checks. This protects operands as
a class instead of enumerating individual dangerous flags.

Git reference: `builtin/branch.c` and `builtin/tag.c` use `parse_options()`
with support for `--` at Git commit
`12cb6293d6288865c1a133cf22accbaf99d13eb6`.

Assisted-by: GPT 6.0
Co-authored-by: GPT 6.0 <[email protected]>
<!-- agent -->
`IndexFile.move()` forwarded paths without an option separator in both
its preliminary dry run and its actual move. A `--force` operand could
overwrite an existing destination, and `--no-dry-run` could move files
even when the caller explicitly requested `dry_run=True`.
`Repo.ignored()` likewise interpreted leading-dash filenames as options.

Insert `--` before paths in both wrappers. The shared move argument list
protects both invocations; explicit keyword options still work. Literal
leading-dash filenames, including values containing spaces, remain usable.
Update the unreleased changelog for both APIs.

Git reference: `builtin/mv.c` and `builtin/check-ignore.c` use
`parse_options()` with `--` support at Git commit
`12cb6293d6288865c1a133cf22accbaf99d13eb6`.

Validation: all four new path regressions failed before the fix. The
positional, index, and repository suites pass 153 tests and 14 subtests,
with four skips, using test-local `init.defaultBranch=master` and
`core.quotePath=true`. One unrelated revision-parsing test was excluded:
it traverses pre-existing checkpoint refs pointing at trees. Tested with
Apple Git 2.54.0; `git diff --check` passes.

Assisted-by: GPT 6.0
Co-authored-by: GPT 6.0 <[email protected]>
<!-- agent -->
`Remote.update()` also crosses an internal Git command boundary: Git's
`remote update` parses options, then forwards the remaining operands to
`fetch --multiple` without an option terminator. A leading-dash remote
name can therefore change the requested operation or its target set.

Reject such names before dispatch. Document at `_call_process()` why
high-level wrappers must protect operands, while the low-level runner
must continue supporting deliberately positional options. Shell quoting
does not affect Git's own option parsing. Add an unreleased changelog entry.

Git reference: `builtin/remote.c:update()` at Git commit
`12cb6293d6288865c1a133cf22accbaf99d13eb6` constructs the internal fetch
command without preserving `--`.

Assisted-by: GPT 6.0
Co-authored-by: GPT 6.0 <[email protected]>

Originally published at github.com. Every curse word you see was added by the Samuel L. Jacksonizer, a parody site. Not affiliated with Samuel L. Jackson or github.com.