Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit d96e3c1

Browse files
pcloudsgitster
authored andcommitted
tag: add --column
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b27004e commit d96e3c1

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ column.status::
870870
Specify whether to output untracked files in `git status` in columns.
871871
See `column.ui` for details.
872872

873+
column.tag::
874+
Specify whether to output tag listing in `git tag` in columns.
875+
See `column.ui` for details.
876+
873877
commit.status::
874878
A boolean to enable/disable inclusion of status information in the
875879
commit message template when using an editor to prepare the commit

Documentation/git-tag.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SYNOPSIS
1313
<tagname> [<commit> | <object>]
1414
'git tag' -d <tagname>...
1515
'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
16+
[--column[=<options>] | --no-column] [<pattern>...]
1617
[<pattern>...]
1718
'git tag' -v <tagname>...
1819

@@ -84,6 +85,14 @@ OPTIONS
8485
using fnmatch(3)). Multiple patterns may be given; if any of
8586
them matches, the tag is shown.
8687

88+
--column[=<options>]::
89+
--no-column::
90+
Display tag listing in columns. See configuration variable
91+
column.tag for option syntax.`--column` and `--no-column`
92+
without options are equivalent to 'always' and 'never' respectively.
93+
+
94+
This option is only applicable when listing tags without annotation lines.
95+
8796
--contains <commit>::
8897
Only list tags which contain the specified commit.
8998

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ builtin/prune.o builtin/reflog.o reachable.o: reachable.h
21682168
builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
21692169
builtin/tar-tree.o archive-tar.o: tar.h
21702170
connect.o transport.o url.o http-backend.o: url.h
2171-
builtin/branch.o builtin/commit.o column.o help.o pager.o: column.h
2171+
builtin/branch.o builtin/commit.o builtin/tag.o column.o help.o pager.o: column.h
21722172
http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
21732173
http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h
21742174

builtin/tag.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "revision.h"
1717
#include "gpg-interface.h"
1818
#include "sha1-array.h"
19+
#include "column.h"
1920

2021
static const char * const git_tag_usage[] = {
2122
"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
@@ -33,6 +34,7 @@ struct tag_filter {
3334
};
3435

3536
static struct sha1_array points_at;
37+
static unsigned int colopts;
3638

3739
static int match_pattern(const char **patterns, const char *ref)
3840
{
@@ -263,6 +265,8 @@ static int git_tag_config(const char *var, const char *value, void *cb)
263265
int status = git_gpg_config(var, value, cb);
264266
if (status)
265267
return status;
268+
if (!prefixcmp(var, "column."))
269+
return git_column_config(var, value, "tag", &colopts);
266270
return git_default_config(var, value, cb);
267271
}
268272

@@ -459,6 +463,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
459463
OPT_STRING('u', "local-user", &keyid, "key-id",
460464
"use another key to sign the tag"),
461465
OPT__FORCE(&force, "replace the tag if exists"),
466+
OPT_COLUMN(0, "column", &colopts, "show tag list in columns"),
462467

463468
OPT_GROUP("Tag listing options"),
464469
{
@@ -495,9 +500,25 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
495500

496501
if (list + delete + verify > 1)
497502
usage_with_options(git_tag_usage, options);
498-
if (list)
499-
return list_tags(argv, lines == -1 ? 0 : lines,
500-
with_commit);
503+
finalize_colopts(&colopts, -1);
504+
if (list && lines != -1) {
505+
if (explicitly_enable_column(colopts))
506+
die(_("--column and -n are incompatible"));
507+
colopts = 0;
508+
}
509+
if (list) {
510+
int ret;
511+
if (column_active(colopts)) {
512+
struct column_options copts;
513+
memset(&copts, 0, sizeof(copts));
514+
copts.padding = 2;
515+
run_column_filter(colopts, &copts);
516+
}
517+
ret = list_tags(argv, lines == -1 ? 0 : lines, with_commit);
518+
if (column_active(colopts))
519+
stop_column_filter();
520+
return ret;
521+
}
501522
if (lines != -1)
502523
die(_("-n option is only allowed with -l."));
503524
if (with_commit)

t/t7004-tag.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,50 @@ test_expect_success 'tag -l can accept multiple patterns' '
263263
test_cmp expect actual
264264
'
265265

266+
test_expect_success 'listing tags in column' '
267+
COLUMNS=40 git tag -l --column=row >actual &&
268+
cat >expected <<\EOF &&
269+
a1 aa1 cba t210 t211
270+
v0.2.1 v1.0 v1.0.1 v1.1.3
271+
EOF
272+
test_cmp expected actual
273+
'
274+
275+
test_expect_success 'listing tags in column with column.*' '
276+
git config column.tag row &&
277+
git config column.ui dense &&
278+
COLUMNS=40 git tag -l >actual &&
279+
git config --unset column.ui &&
280+
git config --unset column.tag &&
281+
cat >expected <<\EOF &&
282+
a1 aa1 cba t210 t211
283+
v0.2.1 v1.0 v1.0.1 v1.1.3
284+
EOF
285+
test_cmp expected actual
286+
'
287+
288+
test_expect_success 'listing tag with -n --column should fail' '
289+
test_must_fail git tag --column -n
290+
'
291+
292+
test_expect_success 'listing tags -n in column with column.ui ignored' '
293+
git config column.ui "row dense" &&
294+
COLUMNS=40 git tag -l -n >actual &&
295+
git config --unset column.ui &&
296+
cat >expected <<\EOF &&
297+
a1 Foo
298+
aa1 Foo
299+
cba Foo
300+
t210 Foo
301+
t211 Foo
302+
v0.2.1 Foo
303+
v1.0 Foo
304+
v1.0.1 Foo
305+
v1.1.3 Foo
306+
EOF
307+
test_cmp expected actual
308+
'
309+
266310
# creating and verifying lightweight tags:
267311

268312
test_expect_success \

0 commit comments

Comments
 (0)