Skip to content

Commit 4de1179

Browse files
committed
Merge branch 'mc/describe-first-parent'
* mc/describe-first-parent: describe: Add --first-parent option
2 parents 103093a + e00dd1e commit 4de1179

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Documentation/git-describe.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ OPTIONS
8888
--always::
8989
Show uniquely abbreviated commit object as fallback.
9090

91+
--first-parent::
92+
Follow only the first parent commit upon seeing a merge commit.
93+
This is useful when you wish to not match tags on branches merged
94+
in the history of the target commit.
95+
9196
EXAMPLES
9297
--------
9398

@@ -149,7 +154,9 @@ is found, its name will be output and searching will stop.
149154
If an exact match was not found, 'git describe' will walk back
150155
through the commit history to locate an ancestor commit which
151156
has been tagged. The ancestor's tag will be output along with an
152-
abbreviation of the input committish's SHA-1.
157+
abbreviation of the input committish's SHA-1. If '--first-parent' was
158+
specified then the walk will only consider the first parent of each
159+
commit.
153160

154161
If multiple tags were found during the walk then the tag which
155162
has the fewest commits different from the input committish will be

builtin/describe.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static int debug; /* Display lots of verbose info */
2121
static int all; /* Any valid ref can be used */
2222
static int tags; /* Allow lightweight tags */
2323
static int longformat;
24+
static int first_parent;
2425
static int abbrev = -1; /* unspecified */
2526
static int max_candidates = 10;
2627
static struct hash_table names;
@@ -336,6 +337,9 @@ static void describe(const char *arg, int last_one)
336337
commit_list_insert_by_date(p, &list);
337338
p->object.flags |= c->object.flags;
338339
parents = parents->next;
340+
341+
if (first_parent)
342+
break;
339343
}
340344
}
341345

@@ -404,6 +408,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
404408
OPT_BOOLEAN(0, "all", &all, N_("use any ref")),
405409
OPT_BOOLEAN(0, "tags", &tags, N_("use any tag, even unannotated")),
406410
OPT_BOOLEAN(0, "long", &longformat, N_("always use long format")),
411+
OPT_BOOLEAN(0, "first-parent", &first_parent, N_("only follow first parent")),
407412
OPT__ABBREV(&abbrev),
408413
OPT_SET_INT(0, "exact-match", &max_candidates,
409414
N_("only output exact matches"), 0),

t/t6120-describe.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ check_describe tags/e --all HEAD^^^
110110
check_describe B-0-* --long HEAD^^2^
111111
check_describe A-3-* --long HEAD^^2
112112

113+
check_describe c-7-* --tags
114+
check_describe e-3-* --first-parent --tags
115+
113116
: >err.expect
114117
check_describe A --all A^0
115118
test_expect_success 'no warning was displayed for A' '

0 commit comments

Comments
 (0)