Skip to content

command: keep working with Git older than 2.43.1 - #146

Merged
unknwon merged 3 commits into
masterfrom
support-old-git-end-of-options
Nov 15, 2026
Merged

unknwon merged 3 commits into
masterfrom
support-old-git-end-of-options

Conversation

@unknwon

@unknwon unknwon commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

#142 passes --end-of-options to every command, but Git 2.24 introduced it and checkout, reset, grep, remote and branch only accept it since Git 2.43.1. With an older Git these commands fail with usage errors, and with a Git older than 2.24 nearly every command does, e.g., rev-list on every repository page of Gogs 0.14 with Git 2.1.4 (gogs/gogs#8215).

Every command runs through RunInDirWithOptions, so the fix is there. With Git 2.43.1 or newer, arguments are unchanged. With an older Git, --end-of-options is dropped and the command refuses to run when an argument after it, up to a -- path separator, starts with a dash. Git would take such an argument as an option, so this keeps the injection protection of #142. The RevParse guard stays as it is. The Git version is only looked up for commands that pass --end-of-options, so git version itself does not recurse. Commands whose arguments after the separator are only paths do not need it: Move now uses --, which every Git version accepts, so a file whose name starts with a dash can still be moved on an older Git. CreateCommit passes the message as --message=<message>, so a message equal to --end-of-options is not taken for the separator. ArgsForBinVersion exposes the same handling for callers that run Git without this package, e.g., Gogs for merges and migrations.

Test plan

  1. Added TestArgsForVersion, a move to and from -runme.sh in TestRepository_Move and a commit with the message --end-of-options in TestRepository_Commit. The last two fail on Git 2.43.0 without the second commit.

  2. Built Git 2.1.4, 2.23.0, 2.30.0, 2.43.0 and 2.43.1 from source and ran the whole suite with each, plus the system Git 2.55.0. Failing tests:

    Git master (v1.8.9) This PR
    2.1.4 68 10
    2.23.0 68 2
    2.30.0 12 2
    2.43.0 8 0
    2.43.1 0 0
    2.55.0 0 0

    None of the remaining failures involve --end-of-options. TestReceivePack and TestUploadPack use --http-backend-info-refs, which is newer than Git 2.30. Git 2.1.4 also lacks remote get-url and grep --column, and does not detect renames in diff by default.

Git 2.24 introduced --end-of-options, but checkout, reset, grep and other
commands only accept it since Git 2.43.1, so with an older Git these commands,
and with a Git older than 2.24 nearly every command, failed with usage errors.
Commands now drop --end-of-options for such a Git and instead refuse to run
when an argument after it starts with a dash, which keeps those arguments from
being taken as options.
@unknwon
unknwon requested a review from a team as a code owner November 15, 2026 03:09
Callers that run Git without this package, e.g., Gogs for merges and
migrations, need the same handling of --end-of-options.
Dropping "--end-of-options" on older Git refuses positional arguments that
start with a dash. Move now separates its paths with "--", which every Git
version accepts, so files whose names start with a dash can still be moved.
CreateCommit attaches the message to its option, so a message equal to
"--end-of-options" is no longer taken for the separator.
@unknwon
unknwon merged commit 5802fa0 into master Nov 15, 2026
4 checks passed
@unknwon
unknwon deleted the support-old-git-end-of-options branch November 15, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant