Skip to content

Commit 1d517ce

Browse files
eli-schwartzgitster
authored andcommitted
pretty: add tag option to %(describe)
The %(describe) placeholder by default, like `git describe`, only supports annotated tags. However, some people do use lightweight tags for releases, and would like to describe those anyway. The command line tool has an option to support this. Teach the placeholder to support this as well. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3c6eb4e commit 1d517ce

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Documentation/pretty-formats.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ The placeholders are:
220220
inconsistent when tags are added or removed at
221221
the same time.
222222
+
223+
** 'tags[=<bool>]': Instead of only considering annotated tags,
224+
consider lightweight tags as well.
223225
** 'match=<pattern>': Only consider tags matching the given
224226
`glob(7)` pattern, excluding the "refs/tags/" prefix.
225227
** 'exclude=<pattern>': Do not consider tags matching the given
@@ -273,11 +275,6 @@ endif::git-rev-list[]
273275
If any option is provided multiple times the
274276
last occurrence wins.
275277
+
276-
The boolean options accept an optional value `[=<BOOL>]`. The values
277-
`true`, `false`, `on`, `off` etc. are all accepted. See the "boolean"
278-
sub-section in "EXAMPLES" in linkgit:git-config[1]. If a boolean
279-
option is given with no value, it's enabled.
280-
+
281278
** 'key=<K>': only show trailers with specified key. Matching is done
282279
case-insensitively and trailing colon is optional. If option is
283280
given multiple times trailer lines matching any of the keys are
@@ -313,6 +310,11 @@ insert an empty string unless we are traversing reflog entries (e.g., by
313310
decoration format if `--decorate` was not already provided on the command
314311
line.
315312

313+
The boolean options accept an optional value `[=<bool>]`. The values
314+
`true`, `false`, `on`, `off` etc. are all accepted. See the "boolean"
315+
sub-section in "EXAMPLES" in linkgit:git-config[1]. If a boolean
316+
option is given with no value, it's enabled.
317+
316318
If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
317319
is inserted immediately before the expansion if and only if the
318320
placeholder expands to a non-empty string.

pretty.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,11 @@ static size_t parse_describe_args(const char *start, struct strvec *args)
12191219
struct {
12201220
char *name;
12211221
enum {
1222+
DESCRIBE_ARG_BOOL,
12221223
DESCRIBE_ARG_STRING,
12231224
} type;
12241225
} option[] = {
1226+
{ "tags", DESCRIBE_ARG_BOOL},
12251227
{ "exclude", DESCRIBE_ARG_STRING },
12261228
{ "match", DESCRIBE_ARG_STRING },
12271229
};
@@ -1231,10 +1233,20 @@ static size_t parse_describe_args(const char *start, struct strvec *args)
12311233
int found = 0;
12321234
const char *argval;
12331235
size_t arglen = 0;
1236+
int optval = 0;
12341237
int i;
12351238

12361239
for (i = 0; !found && i < ARRAY_SIZE(option); i++) {
12371240
switch (option[i].type) {
1241+
case DESCRIBE_ARG_BOOL:
1242+
if (match_placeholder_bool_arg(arg, option[i].name, &arg, &optval)) {
1243+
if (optval)
1244+
strvec_pushf(args, "--%s", option[i].name);
1245+
else
1246+
strvec_pushf(args, "--no-%s", option[i].name);
1247+
found = 1;
1248+
}
1249+
break;
12381250
case DESCRIBE_ARG_STRING:
12391251
if (match_placeholder_arg_value(arg, option[i].name, &arg,
12401252
&argval, &arglen)) {

t/t4205-log-pretty-formats.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,4 +1002,12 @@ test_expect_success '%(describe:exclude=...) vs git describe --exclude ...' '
10021002
test_cmp expect actual
10031003
'
10041004

1005+
test_expect_success '%(describe:tags) vs git describe --tags' '
1006+
test_when_finished "git tag -d tagname" &&
1007+
git tag tagname &&
1008+
git describe --tags >expect &&
1009+
git log -1 --format="%(describe:tags)" >actual &&
1010+
test_cmp expect actual
1011+
'
1012+
10051013
test_done

0 commit comments

Comments
 (0)