Skip to content

Commit

Permalink
Merge branch 'mc/describe-first-parent'
Browse files Browse the repository at this point in the history
* mc/describe-first-parent:
  describe: Add --first-parent option
  • Loading branch information
Junio C Hamano committed Jun 2, 2013
2 parents 103093a + e00dd1e commit 4de1179
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Documentation/git-describe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ OPTIONS
--always::
Show uniquely abbreviated commit object as fallback.

--first-parent::
Follow only the first parent commit upon seeing a merge commit.
This is useful when you wish to not match tags on branches merged
in the history of the target commit.

EXAMPLES
--------

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

If multiple tags were found during the walk then the tag which
has the fewest commits different from the input committish will be
Expand Down
5 changes: 5 additions & 0 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static int debug; /* Display lots of verbose info */
static int all; /* Any valid ref can be used */
static int tags; /* Allow lightweight tags */
static int longformat;
static int first_parent;
static int abbrev = -1; /* unspecified */
static int max_candidates = 10;
static struct hash_table names;
Expand Down Expand Up @@ -336,6 +337,9 @@ static void describe(const char *arg, int last_one)
commit_list_insert_by_date(p, &list);
p->object.flags |= c->object.flags;
parents = parents->next;

if (first_parent)
break;
}
}

Expand Down Expand Up @@ -404,6 +408,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
OPT_BOOLEAN(0, "all", &all, N_("use any ref")),
OPT_BOOLEAN(0, "tags", &tags, N_("use any tag, even unannotated")),
OPT_BOOLEAN(0, "long", &longformat, N_("always use long format")),
OPT_BOOLEAN(0, "first-parent", &first_parent, N_("only follow first parent")),
OPT__ABBREV(&abbrev),
OPT_SET_INT(0, "exact-match", &max_candidates,
N_("only output exact matches"), 0),
Expand Down
3 changes: 3 additions & 0 deletions t/t6120-describe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ check_describe tags/e --all HEAD^^^
check_describe B-0-* --long HEAD^^2^
check_describe A-3-* --long HEAD^^2

check_describe c-7-* --tags
check_describe e-3-* --first-parent --tags

: >err.expect
check_describe A --all A^0
test_expect_success 'no warning was displayed for A' '
Expand Down

0 comments on commit 4de1179

Please sign in to comment.