Git development
 help / color / mirror / Atom feed
From: Laveesh Bansal <laveeshb@laveeshbansal.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Patrick Steinhardt <ps@pks.im>,
	Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH] rev-parse, shortlog: accept --glob with a separate pattern
Date: Sun,  8 Nov 2026 21:24:02 -0800	[thread overview]
Message-ID: <20261109052402.33604-1-laveeshb@laveeshbansal.com> (raw)

"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


                 reply	other threads:[~2026-11-09  5:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261109052402.33604-1-laveeshb@laveeshbansal.com \
    --to=laveeshb@laveeshbansal.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox