Skip to content

Commit 6d3e1f2

Browse files
committed
Merge branch 'mm/status-without-comment-char'
"git status" now omits the prefix to make its output a comment in a commit log editor, which is not necessary for human consumption. We may want to tighten the output to omit unnecessary trailing blank lines, but that does not have to be in the scope of this series. * mm/status-without-comment-char: t7508: avoid non-portable sed expression status: add missing blank line after list of "other" files tests: don't set status.displayCommentPrefix file-wide status: disable display of '#' comment prefix by default submodule summary: ignore --for-status option wt-status: use argv_array API builtin/stripspace.c: fix broken indentation
2 parents 638924f + 2e582df commit 6d3e1f2

11 files changed

+967
-852
lines changed

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,13 @@ status.branch::
21832183
Set to true to enable --branch by default in linkgit:git-status[1].
21842184
The option --no-branch takes precedence over this variable.
21852185

2186+
status.displayCommentPrefix::
2187+
If set to true, linkgit:git-status[1] will insert a comment
2188+
prefix before each output line (starting with
2189+
`core.commentChar`, i.e. `#` by default). This was the
2190+
behavior of linkgit:git-status[1] in Git 1.8.4 and previous.
2191+
Defaults to false.
2192+
21862193
status.showUntrackedFiles::
21872194
By default, linkgit:git-status[1] and linkgit:git-commit[1] show
21882195
files which are not currently tracked by Git. Directories which

builtin/commit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
598598
const char *hook_arg2 = NULL;
599599
int ident_shown = 0;
600600
int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
601+
int old_display_comment_prefix;
601602

602603
/* This checks and barfs if author is badly specified */
603604
determine_author_info(author_ident);
@@ -695,6 +696,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
695696
if (s->fp == NULL)
696697
die_errno(_("could not open '%s'"), git_path(commit_editmsg));
697698

699+
/* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
700+
old_display_comment_prefix = s->display_comment_prefix;
701+
s->display_comment_prefix = 1;
702+
698703
if (clean_message_contents)
699704
stripspace(&sb, 0);
700705

@@ -820,6 +825,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
820825
*/
821826
if (!commitable && whence != FROM_MERGE && !allow_empty &&
822827
!(amend && is_a_merge(current_head))) {
828+
s->display_comment_prefix = old_display_comment_prefix;
823829
run_status(stdout, index_file, prefix, 0, s);
824830
if (amend)
825831
fputs(_(empty_amend_advice), stderr);
@@ -1186,6 +1192,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
11861192
s->use_color = git_config_colorbool(k, v);
11871193
return 0;
11881194
}
1195+
if (!strcmp(k, "status.displaycommentprefix")) {
1196+
s->display_comment_prefix = git_config_bool(k, v);
1197+
return 0;
1198+
}
11891199
if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
11901200
int slot = parse_status_slot(k, 13);
11911201
if (slot < 0)

builtin/stripspace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
8989

9090
if (argc == 2) {
9191
if (!strcmp(argv[1], "-s") ||
92-
!strcmp(argv[1], "--strip-comments")) {
93-
strip_comments = 1;
92+
!strcmp(argv[1], "--strip-comments")) {
93+
strip_comments = 1;
9494
} else if (!strcmp(argv[1], "-c") ||
95-
!strcmp(argv[1], "--comment-lines")) {
96-
mode = COMMENT_LINES;
95+
!strcmp(argv[1], "--comment-lines")) {
96+
mode = COMMENT_LINES;
9797
} else {
9898
mode = INVAL;
9999
}

git-submodule.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,18 +1149,7 @@ cmd_summary() {
11491149
echo
11501150
fi
11511151
echo
1152-
done |
1153-
if test -n "$for_status"; then
1154-
if [ -n "$files" ]; then
1155-
gettextln "Submodules changed but not updated:" | git stripspace -c
1156-
else
1157-
gettextln "Submodule changes to be committed:" | git stripspace -c
1158-
fi
1159-
printf "\n" | git stripspace -c
1160-
git stripspace -c
1161-
else
1162-
cat
1163-
fi
1152+
done
11641153
}
11651154
#
11661155
# List all submodules, prefixed with:

t/t3001-ls-files-others-exclude.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ EOF
115115

116116
git config core.excludesFile excludes-file
117117

118-
git status | grep "^# " > output
118+
git -c status.displayCommentPrefix=true status | grep "^# " > output
119119

120120
cat > expect << EOF
121121
# .gitignore

t/t7060-wtstatus.sh

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@ test_expect_success 'Report new path with conflict' '
2929
test_cmp expect actual
3030
'
3131

32-
cat >expect <<EOF
33-
# On branch side
34-
# You have unmerged paths.
35-
# (fix conflicts and run "git commit")
36-
#
37-
# Unmerged paths:
38-
# (use "git add/rm <file>..." as appropriate to mark resolution)
39-
#
40-
# deleted by us: foo
41-
#
32+
test_expect_success 'M/D conflict does not segfault' '
33+
cat >expect <<EOF &&
34+
On branch side
35+
You have unmerged paths.
36+
(fix conflicts and run "git commit")
37+
38+
Unmerged paths:
39+
(use "git add/rm <file>..." as appropriate to mark resolution)
40+
41+
deleted by us: foo
42+
4243
no changes added to commit (use "git add" and/or "git commit -a")
4344
EOF
44-
45-
test_expect_success 'M/D conflict does not segfault' '
4645
mkdir mdconflict &&
4746
(
4847
cd mdconflict &&
@@ -135,19 +134,19 @@ test_expect_success 'status when conflicts with add and rm advice (deleted by th
135134
test_commit on_second main.txt on_second &&
136135
test_commit master conflict.txt master &&
137136
test_must_fail git merge second_branch &&
138-
cat >expected <<-\EOF &&
139-
# On branch master
140-
# You have unmerged paths.
141-
# (fix conflicts and run "git commit")
142-
#
143-
# Unmerged paths:
144-
# (use "git add/rm <file>..." as appropriate to mark resolution)
145-
#
146-
# both added: conflict.txt
147-
# deleted by them: main.txt
148-
#
149-
no changes added to commit (use "git add" and/or "git commit -a")
150-
EOF
137+
cat >expected <<\EOF &&
138+
On branch master
139+
You have unmerged paths.
140+
(fix conflicts and run "git commit")
141+
142+
Unmerged paths:
143+
(use "git add/rm <file>..." as appropriate to mark resolution)
144+
145+
both added: conflict.txt
146+
deleted by them: main.txt
147+
148+
no changes added to commit (use "git add" and/or "git commit -a")
149+
EOF
151150
git status --untracked-files=no >actual &&
152151
test_i18ncmp expected actual
153152
'
@@ -168,20 +167,20 @@ test_expect_success 'prepare for conflicts' '
168167

169168
test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
170169
test_must_fail git merge conflict &&
171-
cat >expected <<-\EOF &&
172-
# On branch conflict_second
173-
# You have unmerged paths.
174-
# (fix conflicts and run "git commit")
175-
#
176-
# Unmerged paths:
177-
# (use "git add/rm <file>..." as appropriate to mark resolution)
178-
#
179-
# both deleted: main.txt
180-
# added by them: sub_master.txt
181-
# added by us: sub_second.txt
182-
#
183-
no changes added to commit (use "git add" and/or "git commit -a")
184-
EOF
170+
cat >expected <<\EOF &&
171+
On branch conflict_second
172+
You have unmerged paths.
173+
(fix conflicts and run "git commit")
174+
175+
Unmerged paths:
176+
(use "git add/rm <file>..." as appropriate to mark resolution)
177+
178+
both deleted: main.txt
179+
added by them: sub_master.txt
180+
added by us: sub_second.txt
181+
182+
no changes added to commit (use "git add" and/or "git commit -a")
183+
EOF
185184
git status --untracked-files=no >actual &&
186185
test_i18ncmp expected actual
187186
'
@@ -192,22 +191,22 @@ test_expect_success 'status when conflicts with only rm advice (both deleted)' '
192191
test_must_fail git merge conflict &&
193192
git add sub_master.txt &&
194193
git add sub_second.txt &&
195-
cat >expected <<-\EOF &&
196-
# On branch conflict_second
197-
# You have unmerged paths.
198-
# (fix conflicts and run "git commit")
199-
#
200-
# Changes to be committed:
201-
#
202-
# new file: sub_master.txt
203-
#
204-
# Unmerged paths:
205-
# (use "git rm <file>..." to mark resolution)
206-
#
207-
# both deleted: main.txt
208-
#
209-
# Untracked files not listed (use -u option to show untracked files)
210-
EOF
194+
cat >expected <<\EOF &&
195+
On branch conflict_second
196+
You have unmerged paths.
197+
(fix conflicts and run "git commit")
198+
199+
Changes to be committed:
200+
201+
new file: sub_master.txt
202+
203+
Unmerged paths:
204+
(use "git rm <file>..." to mark resolution)
205+
206+
both deleted: main.txt
207+
208+
Untracked files not listed (use -u option to show untracked files)
209+
EOF
211210
git status --untracked-files=no >actual &&
212211
test_i18ncmp expected actual &&
213212
git reset --hard &&

t/t7401-submodule-summary.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,11 @@ EOF
265265
test_expect_success '--for-status' "
266266
git submodule summary --for-status HEAD^ >actual &&
267267
test_i18ncmp actual - <<EOF
268-
# Submodule changes to be committed:
269-
#
270-
# * sm1 $head6...0000000:
271-
#
272-
# * sm2 0000000...$head7 (2):
273-
# > Add foo9
274-
#
268+
* sm1 $head6...0000000:
269+
270+
* sm2 0000000...$head7 (2):
271+
> Add foo9
272+
275273
EOF
276274
"
277275

0 commit comments

Comments
 (0)