diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-02-13 15:09:33 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-02-13 15:09:33 -0800 |
commit | e7c2466593f5c8682a4fe7146f17b80acf134675 (patch) | |
tree | 0fdba9fc0d9b936486b560599b922a2c57c917f1 | |
parent | Start 1.7.1 cycle (diff) | |
parent | accept "git grep -- pattern" (diff) | |
download | tgif-e7c2466593f5c8682a4fe7146f17b80acf134675.tar.xz |
Merge branch 'jk/grep-double-dash'
* jk/grep-double-dash:
accept "git grep -- pattern"
-rw-r--r-- | builtin-grep.c | 10 | ||||
-rwxr-xr-x | t/t7002-grep.sh | 33 |
2 files changed, 43 insertions, 0 deletions
diff --git a/builtin-grep.c b/builtin-grep.c index 26d4deb1cc..63d4b95b0d 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -861,6 +861,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix) PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); + /* + * skip a -- separator; we know it cannot be + * separating revisions from pathnames if + * we haven't even had any patterns yet + */ + if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { + argv++; + argc--; + } + /* First unrecognized non-option token */ if (argc > 0 && !opt.pattern_list) { append_grep_pattern(&opt, argv[0], "command line", 0, diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 7144f815c0..0b583cbfc1 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -434,4 +434,37 @@ test_expect_success 'grep -Fi' ' test_cmp expected actual ' +test_expect_success 'setup double-dash tests' ' +cat >double-dash <<EOF && +-- +-> +other +EOF +git add double-dash +' + +cat >expected <<EOF +double-dash:-> +EOF +test_expect_success 'grep -- pattern' ' + git grep -- "->" >actual && + test_cmp expected actual +' +test_expect_success 'grep -- pattern -- pathspec' ' + git grep -- "->" -- double-dash >actual && + test_cmp expected actual +' +test_expect_success 'grep -e pattern -- path' ' + git grep -e "->" -- double-dash >actual && + test_cmp expected actual +' + +cat >expected <<EOF +double-dash:-- +EOF +test_expect_success 'grep -e -- -- path' ' + git grep -e -- -- double-dash >actual && + test_cmp expected actual +' + test_done |