status: disable display of '#' comment prefix by default
Historically, "git status" needed to prefix each output line with '#' so that the output could be added as comment to the commit message. This prefix comment has no real purpose when "git status" is ran from the command-line, and this may distract users from the real content. Disable this prefix comment by default, and make it re-activable for users needing backward compatibility with status.displayCommentPrefix. Obviously, "git commit" ignores status.displayCommentPrefix and keeps the comment unconditionnaly when writing to COMMIT_EDITMSG (but not when writing to stdout for an error message or with --dry-run). Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Sep 6, 2013 at 19:43 UTC
2556b9962e7c0353d562b7bf70eed11d8f29d0b0
8 files changed
+114
-17
Documentation/config.txt
+7
@@ -2118,6 +2118,13 @@ status.branch::
2118
Set to true to enable --branch by default in linkgit:git-status[1].
2119
The option --no-branch takes precedence over this variable.
2120
2121
+status.displayCommentPrefix::
2122
+ If set to true, linkgit:git-status[1] will insert a comment
2123
+ prefix before each output line (starting with
2124
+ `core.commentChar`, i.e. `#` by default). This was the
2125
+ behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
2126
+ Defaults to false.
2127
+
2128
status.showUntrackedFiles::
2129
By default, linkgit:git-status[1] and linkgit:git-commit[1] show
2130
files which are not currently tracked by Git. Directories which
builtin/commit.c
+10
@@ -599,6 +599,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
599
const char *hook_arg2 = NULL;
600
int ident_shown = 0;
601
int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
602
+ int old_display_comment_prefix;
603
604
/* This checks and barfs if author is badly specified */
605
determine_author_info(author_ident);
@@ -696,6 +697,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
697
if (s->fp == NULL)
698
die_errno(_("could not open '%s'"), git_path(commit_editmsg));
699
700
+ /* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
701
+ old_display_comment_prefix = s->display_comment_prefix;
702
+ s->display_comment_prefix = 1;
703
+
704
if (clean_message_contents)
705
stripspace(&sb, 0);
706
@@ -821,6 +826,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
826
*/
827
if (!commitable && whence != FROM_MERGE && !allow_empty &&
828
!(amend && is_a_merge(current_head))) {
829
+ s->display_comment_prefix = old_display_comment_prefix;
830
run_status(stdout, index_file, prefix, 0, s);
831
if (amend)
832
fputs(_(empty_amend_advice), stderr);
@@ -1182,6 +1188,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
1188
s->use_color = git_config_colorbool(k, v);
1189
return 0;
1190
}
1191
+ if (!strcmp(k, "status.displaycommentprefix")) {
1192
+ s->display_comment_prefix = git_config_bool(k, v);
1193
+ return 0;
1194
+ }
1195
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
1196
int slot = parse_status_slot(k, 13);
1197
if (slot < 0)
t/t3001-ls-files-others-exclude.sh
+1
-1
@@ -115,7 +115,7 @@ EOF
115
116
git config core.excludesFile excludes-file
117
118
-git status | grep "^# " > output
118
+git -c status.displayCommentPrefix=true status | grep "^# " > output
119
120
cat > expect << EOF
121
# .gitignore
t/t7060-wtstatus.sh
+4
@@ -4,6 +4,10 @@ test_description='basic work tree status reporting'
4
5
. ./test-lib.sh
6
7
+test_expect_success 'use status.displayCommentPrefix by default ' '
8
+ git config --global status.displayCommentPrefix true
9
+'
10
+
11
test_expect_success setup '
12
git config --global advice.statusuoption false &&
13
test_commit A &&
t/t7508-status.sh
+58
-5
@@ -7,6 +7,10 @@ test_description='git status'
7
8
. ./test-lib.sh
9
10
+test_expect_success 'use status.displayCommentPrefix by default ' '
11
+ git config --global status.displayCommentPrefix true
12
+'
13
+
14
test_expect_success 'status -h in broken repository' '
15
git config --global advice.statusuoption false &&
16
mkdir broken &&
@@ -60,8 +64,12 @@ test_expect_success 'status (1)' '
64
test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
65
'
66
67
+strip_comments () {
68
+ sed "s/^\# //; s/^\#$//; s/^#\t/\t/" <"$1" >"$1".tmp &&
69
+ rm "$1" && mv "$1".tmp "$1"
70
+}
71
+
72
test_expect_success 'status --column' '
64
- COLUMNS=50 git status --column="column dense" >output &&
73
cat >expect <<\EOF &&
74
# On branch master
75
# Changes to be committed:
@@ -78,9 +86,16 @@ test_expect_success 'status --column' '
86
# Untracked files:
87
# (use "git add <file>..." to include in what will be committed)
88
#
81
-# dir1/untracked dir2/untracked untracked
82
-# dir2/modified output
89
+# dir1/untracked dir2/untracked output
90
+# dir2/modified expect untracked
91
EOF
92
+ COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
93
+ test_i18ncmp expect output
94
+'
95
+
96
+test_expect_success 'status --column status.displayCommentPrefix=false' '
97
+ strip_comments expect &&
98
+ COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
99
test_i18ncmp expect output
100
'
101
@@ -108,11 +123,39 @@ cat >expect <<\EOF
123
# untracked
124
EOF
125
111
-test_expect_success 'status (2)' '
112
- git status >output &&
126
+test_expect_success 'status with status.displayCommentPrefix=true' '
127
+ git -c status.displayCommentPrefix=true status >output &&
128
+ test_i18ncmp expect output
129
+'
130
+
131
+test_expect_success 'status with status.displayCommentPrefix=false' '
132
+ strip_comments expect &&
133
+ git -c status.displayCommentPrefix=false status >output &&
134
test_i18ncmp expect output
135
'
136
137
+test_expect_success 'setup fake editor' '
138
+ cat >.git/editor <<-\EOF &&
139
+ #! /bin/sh
140
+ cp "$1" output
141
+EOF
142
+ chmod 755 .git/editor
143
+'
144
+
145
+commit_template_commented () {
146
+ (
147
+ EDITOR=.git/editor &&
148
+ export EDITOR &&
149
+ # Fails due to empty message
150
+ test_must_fail git commit
151
+ ) &&
152
+ ! grep '^[^#]' output
153
+}
154
+
155
+test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
156
+ commit_template_commented
157
+'
158
+
159
cat >expect <<\EOF
160
# On branch master
161
# Changes to be committed:
@@ -872,6 +915,16 @@ test_expect_success 'status submodule summary' '
915
test_i18ncmp expect output
916
'
917
918
+test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
919
+ strip_comments expect &&
920
+ git -c status.displayCommentPrefix=false status >output &&
921
+ test_i18ncmp expect output
922
+'
923
+
924
+test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
925
+ commit_template_commented
926
+'
927
+
928
cat >expect <<EOF
929
M dir1/modified
930
A dir2/added
t/t7512-status-help.sh
+4
@@ -13,6 +13,10 @@ test_description='git status advice'
13
14
set_fake_editor
15
16
+test_expect_success 'use status.displayCommentPrefix by default ' '
17
+ git config --global status.displayCommentPrefix true
18
+'
19
+
20
test_expect_success 'prepare for conflicts' '
21
git config --global advice.statusuoption false &&
22
test_commit init main.txt init &&
wt-status.c
+29
-11
@@ -46,9 +46,11 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
46
47
strbuf_vaddf(&sb, fmt, ap);
48
if (!sb.len) {
49
- strbuf_addch(&sb, comment_line_char);
50
- if (!trail)
51
- strbuf_addch(&sb, ' ');
49
+ if (s->display_comment_prefix) {
50
+ strbuf_addch(&sb, comment_line_char);
51
+ if (!trail)
52
+ strbuf_addch(&sb, ' ');
53
+ }
54
color_print_strbuf(s->fp, color, &sb);
55
if (trail)
56
fprintf(s->fp, "%s", trail);
@@ -59,7 +61,7 @@ static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
61
eol = strchr(line, '\n');
62
63
strbuf_reset(&linebuf);
62
- if (at_bol) {
64
+ if (at_bol && s->display_comment_prefix) {
65
strbuf_addch(&linebuf, comment_line_char);
66
if (*line != '\n' && *line != '\t')
67
strbuf_addch(&linebuf, ' ');
@@ -129,6 +131,7 @@ void wt_status_prepare(struct wt_status *s)
131
s->untracked.strdup_strings = 1;
132
s->ignored.strdup_strings = 1;
133
s->show_branch = -1; /* unspecified */
134
+ s->display_comment_prefix = 0;
135
}
136
137
static void wt_status_print_unmerged_header(struct wt_status *s)
@@ -707,9 +710,11 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
710
strbuf_addbuf(&summary, &cmd_stdout);
711
strbuf_release(&cmd_stdout);
712
710
- summary_content = strbuf_detach(&summary, &len);
711
- strbuf_add_commented_lines(&summary, summary_content, len);
712
- free(summary_content);
713
+ if (s->display_comment_prefix) {
714
+ summary_content = strbuf_detach(&summary, &len);
715
+ strbuf_add_commented_lines(&summary, summary_content, len);
716
+ free(summary_content);
717
+ }
718
719
fputs(summary.buf, s->fp);
720
strbuf_release(&summary);
@@ -748,8 +753,9 @@ static void wt_status_print_other(struct wt_status *s,
753
if (!column_active(s->colopts))
754
return;
755
751
- strbuf_addf(&buf, "%s#\t%s",
756
+ strbuf_addf(&buf, "%s%s\t%s",
757
color(WT_STATUS_HEADER, s),
758
+ s->display_comment_prefix ? "#" : "",
759
color(WT_STATUS_UNTRACKED, s));
760
memset(&copts, 0, sizeof(copts));
761
copts.padding = 1;
@@ -793,6 +799,8 @@ static void wt_status_print_tracking(struct wt_status *s)
799
struct strbuf sb = STRBUF_INIT;
800
const char *cp, *ep;
801
struct branch *branch;
802
+ char comment_line_string[3];
803
+ int i;
804
805
assert(s->branch && !s->is_initial);
806
if (prefixcmp(s->branch, "refs/heads/"))
@@ -801,12 +809,22 @@ static void wt_status_print_tracking(struct wt_status *s)
809
if (!format_tracking_info(branch, &sb))
810
return;
811
812
+ i = 0;
813
+ if (s->display_comment_prefix) {
814
+ comment_line_string[i++] = comment_line_char;
815
+ comment_line_string[i++] = ' ';
816
+ }
817
+ comment_line_string[i] = '\0';
818
+
819
for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
820
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
806
- "%c %.*s", comment_line_char,
821
+ "%s%.*s", comment_line_string,
822
(int)(ep - cp), cp);
808
- color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
809
- comment_line_char);
823
+ if (s->display_comment_prefix)
824
+ color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
825
+ comment_line_char);
826
+ else
827
+ fprintf_ln(s->fp, "");
828
}
829
830
static int has_unmerged(struct wt_status *s)
wt-status.h
+1
@@ -50,6 +50,7 @@ struct wt_status {
50
enum commit_whence whence;
51
int nowarn;
52
int use_color;
53
+ int display_comment_prefix;
54
int relative_paths;
55
int submodule_summary;
56
int show_ignored_files;