Skip to content

Commit 3085f94

Browse files
committed
Merge branch 'rs/describe-parseopt-fix'
Command line parser fix. * rs/describe-parseopt-fix: describe: fix --no-exact-match
2 parents c8a33b4 + c95ae3f commit 3085f94

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

builtin/describe.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "wildmatch.h"
2626

2727
#define MAX_TAGS (FLAG_BITS - 1)
28+
#define DEFAULT_CANDIDATES 10
2829

2930
define_commit_slab(commit_names, struct commit_name *);
3031

@@ -41,7 +42,7 @@ static int tags; /* Allow lightweight tags */
4142
static int longformat;
4243
static int first_parent;
4344
static int abbrev = -1; /* unspecified */
44-
static int max_candidates = 10;
45+
static int max_candidates = DEFAULT_CANDIDATES;
4546
static struct hashmap names;
4647
static int have_util;
4748
static struct string_list patterns = STRING_LIST_INIT_NODUP;
@@ -557,6 +558,15 @@ static void describe(const char *arg, int last_one)
557558
strbuf_release(&sb);
558559
}
559560

561+
static int option_parse_exact_match(const struct option *opt, const char *arg,
562+
int unset)
563+
{
564+
BUG_ON_OPT_ARG(arg);
565+
566+
max_candidates = unset ? DEFAULT_CANDIDATES : 0;
567+
return 0;
568+
}
569+
560570
int cmd_describe(int argc, const char **argv, const char *prefix)
561571
{
562572
int contains = 0;
@@ -568,8 +578,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
568578
OPT_BOOL(0, "long", &longformat, N_("always use long format")),
569579
OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
570580
OPT__ABBREV(&abbrev),
571-
OPT_SET_INT(0, "exact-match", &max_candidates,
572-
N_("only output exact matches"), 0),
581+
OPT_CALLBACK_F(0, "exact-match", NULL, NULL,
582+
N_("only output exact matches"),
583+
PARSE_OPT_NOARG, option_parse_exact_match),
573584
OPT_INTEGER(0, "candidates", &max_candidates,
574585
N_("consider <n> most recent tags (default: 10)")),
575586
OPT_STRING_LIST(0, "match", &patterns, N_("pattern"),

t/t6120-describe.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ check_describe e-1-gHASH --tags HEAD^^
8585
check_describe c-2-gHASH --tags HEAD^^2
8686
check_describe B --tags HEAD^^2^
8787
check_describe e --tags HEAD^^^
88+
check_describe e --tags --exact-match HEAD^^^
8889

8990
check_describe heads/main --all HEAD
9091
check_describe tags/c-6-gHASH --all HEAD^
@@ -96,6 +97,13 @@ check_describe A-3-gHASH --long HEAD^^2
9697
check_describe c-7-gHASH --tags
9798
check_describe e-3-gHASH --first-parent --tags
9899

100+
check_describe c-7-gHASH --tags --no-exact-match HEAD
101+
check_describe e-3-gHASH --first-parent --tags --no-exact-match HEAD
102+
103+
test_expect_success '--exact-match failure' '
104+
test_must_fail git describe --exact-match HEAD 2>err
105+
'
106+
99107
test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
100108
echo "A^0" >expect &&
101109
git checkout A &&

0 commit comments

Comments
 (0)