# [PATCH] rev-parse, shortlog: accept --glob with a separate pattern

1 messages from 2026-11-09 to 2026-11-09. Participants: Laveesh Bansal.
Thread: https://gitlist.dev/t/66808

## Laveesh Bansal, 2026-11-09 05:24

Subject: [PATCH] rev-parse, shortlog: accept --glob with a separate pattern
Message-ID: <20261109052402.33604-1-laveeshb@laveeshbansal.com>
URL: https://gitlist.dev/e/20261109052402.33604-1-laveeshb%40laveeshbansal.com

```
"git log --glob <pattern>" works, but the other two commands only
understand "--glob=<pattern>":

    $ git rev-parse --glob 'heads/*'
    --glob
    heads/*

    $ git shortlog --glob 'heads/*'
    error: unknown option `--glob'

0fc63ec4e7 (revisions: allow --glob and friends in
parse_options-enabled commands, 2011-04-21) only recognised the
"--glob=" spelling for commands that parse options in two stages, and
"git rev-parse" parses it by hand. Accept the separate word in both.

The four tests that commit added as known breakage now pass, so turn
them into regular tests.

Assisted-by: LLM
Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
---

Notes:
    This only covers --glob. --exclude and --exclude-hidden have the same
    gap and I will send them separately. --branches, --tags and --remotes
    take an optional argument, so they stay in the "=" form.

 builtin/rev-parse.c      | 4 ++++
 revision.c               | 6 ++++++
 t/t6018-rev-list-glob.sh | 8 ++++----
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index ec33c19bdf..c1ea7e81af 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -972,6 +972,10 @@ int cmd_rev_parse(int argc,
 				handle_ref_opt(arg, NULL);
 				continue;
 			}
+			if (!strcmp(arg, "--glob") && i + 1 < argc) {
+				handle_ref_opt(argv[++i], NULL);
+				continue;
+			}
 			if (opt_with_value(arg, "--remotes", &arg)) {
 				if (ref_excludes.hidden_refs_configured)
 					return error(_("options '%s' and '%s' cannot be used together"),
diff --git a/revision.c b/revision.c
index a83e499047..df75c58bc7 100644
--- a/revision.c
+++ b/revision.c
@@ -2355,6 +2355,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	const unsigned hexsz = the_hash_algo->hexsz;
 
 	/* pseudo revision arguments */
+	if (!strcmp(arg, "--glob") && argc > 1) {
+		overwrite_argv(unkc, unkv, &argv[0], opt, revs);
+		overwrite_argv(unkc, unkv, &argv[1], opt, revs);
+		return 2;
+	}
+
 	if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") ||
 	    !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
 	    !strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh
index bb55c7e3c3..01f064bc9e 100755
--- a/t/t6018-rev-list-glob.sh
+++ b/t/t6018-rev-list-glob.sh
@@ -78,13 +78,13 @@ 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"
 
@@ -409,7 +409,7 @@ test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
 
 '
 
-test_expect_failure 'shortlog accepts --glob as detached option' '
+test_expect_success 'shortlog accepts --glob as detached option' '
 
 	compare shortlog \
 	  "main other/three someref subspace-x subspace/one subspace/two" \
@@ -417,7 +417,7 @@ test_expect_failure 'shortlog accepts --glob as detached option' '
 
 '
 
-test_expect_failure 'shortlog --glob is not confused by option-like argument' '
+test_expect_success 'shortlog --glob is not confused by option-like argument' '
 
 	compare shortlog main "--glob -e main"
 
-- 
2.54.0



```
