Skip to content

Commit 0fc63ec

Browse files
jrngitster
authored andcommitted
revisions: allow --glob and friends in parse_options-enabled commands
As v1.6.0-rc2~42 (2008-07-31) explains, even pseudo-options like --not and --glob that need to be parsed in order with revisions should be marked handled by handle_revision_opt to avoid an error when parse_revision_opt callers like "git shortlog" encounter them. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6aca0d commit 0fc63ec

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

revision.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
11781178
!strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
11791179
!strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
11801180
!strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
1181-
!strcmp(arg, "--bisect"))
1181+
!strcmp(arg, "--bisect") || !prefixcmp(arg, "--glob=") ||
1182+
!prefixcmp(arg, "--branches=") || !prefixcmp(arg, "--tags=") ||
1183+
!prefixcmp(arg, "--remotes="))
11821184
{
11831185
unkv[(*unkc)++] = arg;
11841186
return 1;
@@ -1534,6 +1536,16 @@ static int handle_revision_pseudo_opt(const char *submodule,
15341536
const char *optarg;
15351537
int argcount;
15361538

1539+
/*
1540+
* NOTE!
1541+
*
1542+
* Commands like "git shortlog" will not accept the options below
1543+
* unless parse_revision_opt queues them (as opposed to erroring
1544+
* out).
1545+
*
1546+
* When implementing your new pseudo-option, remember to
1547+
* register it in the list at the top of handle_revision_opt.
1548+
*/
15371549
if (!strcmp(arg, "--all")) {
15381550
handle_refs(submodule, revs, *flags, for_each_ref_submodule);
15391551
handle_refs(submodule, revs, *flags, head_ref_submodule);

t/t6018-rev-list-glob.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ test_expect_success 'rev-parse --glob=heads/subspace' '
6969
7070
'
7171

72+
test_expect_failure 'rev-parse accepts --glob as detached option' '
73+
74+
compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
75+
76+
'
77+
78+
test_expect_failure 'rev-parse is not confused by option-like glob' '
79+
80+
compare rev-parse "master" "--glob --symbolic master"
81+
82+
'
83+
7284
test_expect_success 'rev-parse --branches=subspace/*' '
7385
7486
compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
@@ -129,6 +141,12 @@ test_expect_success 'rev-list --glob refs/heads/subspace/*' '
129141
130142
'
131143

144+
test_expect_success 'rev-list not confused by option-like --glob arg' '
145+
146+
compare rev-list "master" "--glob -0 master"
147+
148+
'
149+
132150
test_expect_success 'rev-list --glob=heads/subspace/*' '
133151
134152
compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
@@ -213,4 +231,36 @@ test_expect_success 'rev-list --remotes=foo' '
213231
214232
'
215233

234+
test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
235+
236+
compare shortlog "subspace/one subspace/two" --branches=subspace &&
237+
compare shortlog \
238+
"master subspace-x someref other/three subspace/one subspace/two" \
239+
--branches &&
240+
compare shortlog master "--glob=heads/someref/* master" &&
241+
compare shortlog "subspace/one subspace/two other/three" \
242+
"--glob=heads/subspace/* --glob=heads/other/*" &&
243+
compare shortlog \
244+
"master other/three someref subspace-x subspace/one subspace/two" \
245+
"--glob=heads/*" &&
246+
compare shortlog foo/bar --tags=foo &&
247+
compare shortlog foo/bar --tags &&
248+
compare shortlog foo/baz --remotes=foo
249+
250+
'
251+
252+
test_expect_failure 'shortlog accepts --glob as detached option' '
253+
254+
compare shortlog \
255+
"master other/three someref subspace-x subspace/one subspace/two" \
256+
"--glob heads/*"
257+
258+
'
259+
260+
test_expect_failure 'shortlog --glob is not confused by option-like argument' '
261+
262+
compare shortlog master "--glob -e master"
263+
264+
'
265+
216266
test_done

0 commit comments

Comments
 (0)