Repository navigation
command: keep working with Git older than 2.43.1 - #146
Merged
Merged
Conversation
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.
Callers that run Git without this package, e.g., Gogs for merges and migrations, need the same handling of --end-of-options.
3 of 4 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
#142 passes
--end-of-optionsto every command, but Git 2.24 introduced it andcheckout,reset,grep,remoteandbranchonly 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-liston 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-optionsis 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. TheRevParseguard stays as it is. The Git version is only looked up for commands that pass--end-of-options, sogit versionitself does not recurse. Commands whose arguments after the separator are only paths do not need it:Movenow uses--, which every Git version accepts, so a file whose name starts with a dash can still be moved on an older Git.CreateCommitpasses the message as--message=<message>, so a message equal to--end-of-optionsis not taken for the separator.ArgsForBinVersionexposes the same handling for callers that run Git without this package, e.g., Gogs for merges and migrations.Test plan
Added
TestArgsForVersion, a move to and from-runme.shinTestRepository_Moveand a commit with the message--end-of-optionsinTestRepository_Commit. The last two fail on Git 2.43.0 without the second commit.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:
master(v1.8.9)None of the remaining failures involve
--end-of-options.TestReceivePackandTestUploadPackuse--http-backend-info-refs, which is newer than Git 2.30. Git 2.1.4 also lacksremote get-urlandgrep --column, and does not detect renames indiffby default.