With a branch named topic/one, "git rev-parse --glob=heads/topic" prints its object ID. Passing "heads/topic" as a separate argument instead makes rev-parse echo "--glob" and try to resolve "heads/topic" on its own. rev-list already accepts both forms. Consume the next argument as the pattern, even if it looks like an option. As in rev-list, a bare "--" still separates revisions from paths, so report a missing pattern if it immediately follows --glob. Turn the two corresponding known failures in t6018 into expected successes and exercise the missing-pattern diagnostic. Signed-off-by: Christian Sagstetter <chri…@gmail.com> --- Documentation/git-rev-parse.adoc | 1 + builtin/rev-parse.c | 7 ++++++- t/t6018-rev-list-glob.sh | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation/git-rev-parse.adoc b/Documentation/git-rev-parse.adoc index 9103d54d53..1181ce3b08 100644 --- a/Documentation/git-rev-parse.adoc +++ b/Documentation/git-rev-parse.adoc @@ -201,6 +201,7 @@ shown. If the pattern does not contain a globbing character (`?`, `*`, or `[`), it is turned into a prefix match by appending `/*`. --glob=<pattern>:: +--glob <pattern>:: Show all refs matching the shell glob pattern `pattern`. If the pattern does not start with `refs/`, this is automatically prepended. If the pattern does not contain a globbing diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 25a1e05714..56cc49c0f3 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -969,7 +969,12 @@ int cmd_rev_parse(int argc, handle_ref_opt(arg, "refs/tags/"); continue; } - if (skip_prefix(arg, "--glob=", &arg)) { + if (opt_with_value(arg, "--glob", &arg)) { + if (!arg) { + arg = argv[++i]; + if (!arg || !strcmp(arg, "--")) + die(_("--glob requires an argument")); + } handle_ref_opt(arg, NULL); continue; } diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index bb55c7e3c3..e9022554e2 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -78,18 +78,25 @@ test_expect_success 'rev-parse --glob=heads/subspace' ' ' -test_expect_failure 'rev-parse accepts --glob as detached option' ' +test_expect_success 'rev-parse accepts --glob as detached option' ' compare rev-parse "subspace/one subspace/two" "--glob heads/subspace" ' -test_expect_failure 'rev-parse is not confused by option-like glob' ' +test_expect_success 'rev-parse is not confused by option-like glob' ' compare rev-parse "main" "--glob --symbolic main" ' +test_expect_success 'rev-parse --glob requires a pattern' ' + test_must_fail git rev-parse --glob 2>err && + test_grep "glob requires an argument" err && + test_must_fail git rev-parse --glob -- foo 2>err && + test_grep "glob requires an argument" err +' + test_expect_success 'rev-parse --branches=subspace/*' ' compare rev-parse "subspace/one subspace/two" "--branches=subspace/*" base-commit: 566b6997dd4710b625c0882cf10a7443bf52d183
-- 2.53.0