Skip to content

Commit e95c3fb

Browse files
committed
Merge branch 'sg/describe-contains'
"git describe" without argument defaulted to describe the HEAD commit, but "git describe --contains" didn't. Arguably, in a repository used for active development, such defaulting would not be very useful as the tip of branch is typically not tagged, but it is better to be consistent. * sg/describe-contains: describe --contains: default to HEAD when no commit-ish is given
2 parents b21089d + 2bd0706 commit e95c3fb

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Documentation/git-describe.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-describe - Describe a commit using the most recent tag reachable from it
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] <commit-ish>...
12+
'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>...]
1313
'git describe' [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]
1414

1515
DESCRIPTION
@@ -27,7 +27,7 @@ see the -a and -s options to linkgit:git-tag[1].
2727
OPTIONS
2828
-------
2929
<commit-ish>...::
30-
Commit-ish object names to describe.
30+
Commit-ish object names to describe. Defaults to HEAD if omitted.
3131

3232
--dirty[=<mark>]::
3333
Describe the working tree.

builtin/describe.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
443443
if (pattern)
444444
argv_array_pushf(&args, "--refs=refs/tags/%s", pattern);
445445
}
446-
while (*argv) {
447-
argv_array_push(&args, *argv);
448-
argv++;
449-
}
446+
if (argc)
447+
argv_array_pushv(&args, argv);
448+
else
449+
argv_array_push(&args, "HEAD");
450450
return cmd_name_rev(args.argc, args.argv, prefix);
451451
}
452452

t/t6120-describe.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ check_describe A-3-* --long HEAD^^2
113113
check_describe c-7-* --tags
114114
check_describe e-3-* --first-parent --tags
115115

116+
test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
117+
echo "A^0" >expect &&
118+
git checkout A &&
119+
test_when_finished "git checkout -" &&
120+
git describe --contains >actual &&
121+
test_cmp expect actual
122+
'
123+
116124
: >err.expect
117125
check_describe A --all A^0
118126
test_expect_success 'no warning was displayed for A' '

0 commit comments

Comments
 (0)