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

Commit 323d053

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

File tree

7 files changed

+70
-3
lines changed

7 files changed

+70
-3
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,10 @@ column.branch::
866866
Specify whether to output branch listing in `git branch` in columns.
867867
See `column.ui` for details.
868868

869+
column.status::
870+
Specify whether to output untracked files in `git status` in columns.
871+
See `column.ui` for details.
872+
869873
commit.status::
870874
A boolean to enable/disable inclusion of status information in the
871875
commit message template when using an editor to prepare the commit

Documentation/git-status.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ configuration variable documented in linkgit:git-config[1].
7777
Terminate entries with NUL, instead of LF. This implies
7878
the `--porcelain` output format if no other format is given.
7979

80+
--column[=<options>]::
81+
--no-column::
82+
Display untracked files in columns. See configuration variable
83+
column.status for option syntax.`--column` and `--no-column`
84+
without options are equivalent to 'always' and 'never'
85+
respectively.
86+
8087

8188
OUTPUT
8289
------

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 column.o help.o pager.o: column.h
2171+
builtin/branch.o builtin/commit.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/commit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "quote.h"
2828
#include "submodule.h"
2929
#include "gpg-interface.h"
30+
#include "column.h"
3031

3132
static const char * const builtin_commit_usage[] = {
3233
"git commit [options] [--] <filepattern>...",
@@ -88,6 +89,7 @@ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
8889
static int no_post_rewrite, allow_empty_message;
8990
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
9091
static char *sign_commit;
92+
static unsigned int colopts;
9193

9294
/*
9395
* The default commit message cleanup mode will remove the lines
@@ -1145,6 +1147,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
11451147
{
11461148
struct wt_status *s = cb;
11471149

1150+
if (!prefixcmp(k, "column."))
1151+
return git_column_config(k, v, "status", &colopts);
11481152
if (!strcmp(k, "status.submodulesummary")) {
11491153
int is_bool;
11501154
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
@@ -1210,6 +1214,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12101214
{ OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
12111215
"ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
12121216
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
1217+
OPT_COLUMN(0, "column", &colopts, "list untracked files in columns"),
12131218
OPT_END(),
12141219
};
12151220

@@ -1223,6 +1228,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12231228
argc = parse_options(argc, argv, prefix,
12241229
builtin_status_options,
12251230
builtin_status_usage, 0);
1231+
finalize_colopts(&colopts, -1);
1232+
s.colopts = colopts;
12261233

12271234
if (null_termination && status_format == STATUS_FORMAT_LONG)
12281235
status_format = STATUS_FORMAT_PORCELAIN;

t/t7508-status.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ test_expect_success 'status (1)' '
5959
test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
6060
'
6161

62+
test_expect_success 'status --column' '
63+
COLUMNS=50 git status --column="column dense" >output &&
64+
cat >expect <<\EOF &&
65+
# On branch master
66+
# Changes to be committed:
67+
# (use "git reset HEAD <file>..." to unstage)
68+
#
69+
# new file: dir2/added
70+
#
71+
# Changes not staged for commit:
72+
# (use "git add <file>..." to update what will be committed)
73+
# (use "git checkout -- <file>..." to discard changes in working directory)
74+
#
75+
# modified: dir1/modified
76+
#
77+
# Untracked files:
78+
# (use "git add <file>..." to include in what will be committed)
79+
#
80+
# dir1/untracked dir2/untracked untracked
81+
# dir2/modified output
82+
EOF
83+
test_cmp expect output
84+
'
85+
6286
cat >expect <<\EOF
6387
# On branch master
6488
# Changes to be committed:

wt-status.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "remote.h"
1212
#include "refs.h"
1313
#include "submodule.h"
14+
#include "column.h"
1415

1516
static char default_wt_status_colors[][COLOR_MAXLEN] = {
1617
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -641,6 +642,8 @@ static void wt_status_print_other(struct wt_status *s,
641642
{
642643
int i;
643644
struct strbuf buf = STRBUF_INIT;
645+
static struct string_list output = STRING_LIST_INIT_DUP;
646+
struct column_options copts;
644647

645648
if (!l->nr)
646649
return;
@@ -649,12 +652,33 @@ static void wt_status_print_other(struct wt_status *s,
649652

650653
for (i = 0; i < l->nr; i++) {
651654
struct string_list_item *it;
655+
const char *path;
652656
it = &(l->items[i]);
657+
path = quote_path(it->string, strlen(it->string),
658+
&buf, s->prefix);
659+
if (column_active(s->colopts)) {
660+
string_list_append(&output, path);
661+
continue;
662+
}
653663
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
654664
status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
655-
"%s\n", quote_path(it->string, strlen(it->string),
656-
&buf, s->prefix));
665+
"%s\n", path);
657666
}
667+
668+
strbuf_release(&buf);
669+
if (!column_active(s->colopts))
670+
return;
671+
672+
strbuf_addf(&buf, "%s#\t%s",
673+
color(WT_STATUS_HEADER, s),
674+
color(WT_STATUS_UNTRACKED, s));
675+
memset(&copts, 0, sizeof(copts));
676+
copts.padding = 1;
677+
copts.indent = buf.buf;
678+
if (want_color(s->use_color))
679+
copts.nl = GIT_COLOR_RESET "\n";
680+
print_columns(&output, s->colopts, &copts);
681+
string_list_clear(&output, 0);
658682
strbuf_release(&buf);
659683
}
660684

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct wt_status {
5656
enum untracked_status_type show_untracked_files;
5757
const char *ignore_submodule_arg;
5858
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59+
int colopts;
5960

6061
/* These are computed during processing of the individual sections */
6162
int commitable;

0 commit comments

Comments
 (0)