Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-11-11 00:37:27 +0300
committerJunio C Hamano <gitster@pobox.com>2020-11-11 00:46:27 +0300
commite05e2ae8fe6e5d83254c27664c66bc47b270b6d2 (patch)
treeec3e6e1bdc1bb112f816fcc0743e254a20e1d0b3 /t/t1506-rev-parse-diagnosis.sh
parent898f80736c75878acc02dc55672317fcc0e0a5a6 (diff)
rev-parse: don't accept options after dashdash
Because of the order in which we check options in rev-parse, there are a few options we accept even after a "--". This is wrong, because the whole point of "--" is to say "everything after here is a path". Let's move the "did we see a dashdash" check (it's called "as_is" in the code) to the top of the parsing loop. Note there is one subtlety here. The options are ordered so that some are checked before we even see if we're in a repository (they continue the loop, and if we get past a certain point, then we do the repository setup). By moving the as_is check higher, it's also in that "before setup" section, even though it might look at the repository via verify_filename(). However, this works out: we'd never set as_is until we parse "--", and we don't parse that until after doing the setup. An alternative here to avoid the subtlety is to put the as_is check at the top of the post-setup options. But then every pre-setup option would have to remember to check "if (!as_is && !strcmp(...))". So while this is a bit magical, it's harder for future code to get wrong. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1506-rev-parse-diagnosis.sh')
-rwxr-xr-xt/t1506-rev-parse-diagnosis.sh9
1 files changed, 9 insertions, 0 deletions
diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh
index 3e657e693b..2ed5d50059 100755
--- a/t/t1506-rev-parse-diagnosis.sh
+++ b/t/t1506-rev-parse-diagnosis.sh
@@ -254,4 +254,13 @@ test_expect_success 'escaped char does not trigger wildcard rule' '
test_must_fail git rev-parse "foo\\*bar"
'
+test_expect_success 'arg after dashdash not interpreted as option' '
+ cat >expect <<-\EOF &&
+ --
+ --local-env-vars
+ EOF
+ git rev-parse -- --local-env-vars >actual &&
+ test_cmp expect actual
+'
+
test_done