status: fix missing newline when comment chars are disabled

When git-status shows tracking data for the current branch in the long format, we try to end the stanza with a blank line. When status.displayCommentPrefix is true, we call color_fprintf_ln() to do so. But when it's false, we call the enigmatic: fputs("", s->fp); which does nothing at all! This is a bug from 7d7d68022 (silence a bunch of format-zero-length warnings, 2014-05-04). Prior to that, we called fprintf_ln() with an empty string. Switching to fputs() meant we needed to include the "newline in the string, but we didn't. So you see: On branch jk/status-tracking-newline Your branch is ahead of 'origin/master' by 1 commit. Changes not staged for commit: modified: foo Untracked files: bar whereas there should be a blank line before the "Changes not staged" line. The fix itself is a one-liner. But we never noticed this bug because t7508 doesn't exercise the ahead/behind code at all. So let's configure an upstream during the initial setup, which means that the code will be exercised as part of all of the various invocations in that script. This makes the diff rather noisy, but should give us good coverage. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 27, 2017 at 05:01 UTC 75177c8591aee23374c2ead9c9505ce989a8eec2
2 files changed +112 -5
t/t7508-status.sh
+111 -4
@@ -32,6 +32,17 @@ test_expect_success 'commit -h in broken repository' '
32 test_i18ngrep "[Uu]sage" broken/usage
33 '
34
35 +test_expect_success 'create upstream branch' '
36 + git checkout -b upstream &&
37 + test_commit upstream1 &&
38 + test_commit upstream2 &&
39 + # leave the first commit on master as root because several
40 + # tests depend on this case; for our upstream we only
41 + # care about commit counts anyway, so a totally divergent
42 + # history is OK
43 + git checkout --orphan master
44 +'
45 +
46 test_expect_success 'setup' '
47 : >tracked &&
48 : >modified &&
@@ -53,7 +64,9 @@ test_expect_success 'setup' '
64 echo 1 >dir1/modified &&
65 echo 2 >dir2/modified &&
66 echo 3 >dir2/added &&
56 - git add dir2/added
67 + git add dir2/added &&
68 +
69 + git branch --set-upstream-to=upstream
70 '
71
72 test_expect_success 'status (1)' '
@@ -75,6 +88,10 @@ EOF
88 test_expect_success 'status --column' '
89 cat >expect <<\EOF &&
90 # On branch master
91 +# Your branch and '\''upstream'\'' have diverged,
92 +# and have 1 and 2 different commits each, respectively.
93 +# (use "git pull" to merge the remote branch into yours)
94 +#
95 # Changes to be committed:
96 # (use "git reset HEAD <file>..." to unstage)
97 #
@@ -105,6 +122,10 @@ test_expect_success 'status --column status.displayCommentPrefix=false' '
122
123 cat >expect <<\EOF
124 # On branch master
125 +# Your branch and 'upstream' have diverged,
126 +# and have 1 and 2 different commits each, respectively.
127 +# (use "git pull" to merge the remote branch into yours)
128 +#
129 # Changes to be committed:
130 # (use "git reset HEAD <file>..." to unstage)
131 #
@@ -178,6 +199,9 @@ test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_
199
200 cat >expect <<\EOF
201 On branch master
202 +Your branch and 'upstream' have diverged,
203 +and have 1 and 2 different commits each, respectively.
204 +
205 Changes to be committed:
206 new file: dir2/added
207
@@ -248,6 +272,10 @@ test_expect_success 'status with gitignore' '
272
273 cat >expect <<\EOF &&
274 On branch master
275 +Your branch and '\''upstream'\'' have diverged,
276 +and have 1 and 2 different commits each, respectively.
277 + (use "git pull" to merge the remote branch into yours)
278 +
279 Changes to be committed:
280 (use "git reset HEAD <file>..." to unstage)
281
@@ -313,6 +341,10 @@ test_expect_success 'status with gitignore (nothing untracked)' '
341
342 cat >expect <<\EOF &&
343 On branch master
344 +Your branch and '\''upstream'\'' have diverged,
345 +and have 1 and 2 different commits each, respectively.
346 + (use "git pull" to merge the remote branch into yours)
347 +
348 Changes to be committed:
349 (use "git reset HEAD <file>..." to unstage)
350
@@ -348,7 +380,7 @@ output*
380 EOF
381
382 cat >expect <<\EOF
351 -## master
383 +## master...upstream [ahead 1, behind 2]
384 M dir1/modified
385 A dir2/added
386 ?? dir1/untracked
@@ -382,6 +414,10 @@ test_expect_success 'setup dir3' '
414 test_expect_success 'status -uno' '
415 cat >expect <<EOF &&
416 On branch master
417 +Your branch and '\''upstream'\'' have diverged,
418 +and have 1 and 2 different commits each, respectively.
419 + (use "git pull" to merge the remote branch into yours)
420 +
421 Changes to be committed:
422 (use "git reset HEAD <file>..." to unstage)
423
@@ -408,6 +444,9 @@ test_expect_success 'status (status.showUntrackedFiles no)' '
444 test_expect_success 'status -uno (advice.statusHints false)' '
445 cat >expect <<EOF &&
446 On branch master
447 +Your branch and '\''upstream'\'' have diverged,
448 +and have 1 and 2 different commits each, respectively.
449 +
450 Changes to be committed:
451 new file: dir2/added
452
@@ -439,6 +478,10 @@ test_expect_success 'status -s (status.showUntrackedFiles no)' '
478 test_expect_success 'status -unormal' '
479 cat >expect <<EOF &&
480 On branch master
481 +Your branch and '\''upstream'\'' have diverged,
482 +and have 1 and 2 different commits each, respectively.
483 + (use "git pull" to merge the remote branch into yours)
484 +
485 Changes to be committed:
486 (use "git reset HEAD <file>..." to unstage)
487
@@ -493,6 +536,10 @@ test_expect_success 'status -s (status.showUntrackedFiles normal)' '
536 test_expect_success 'status -uall' '
537 cat >expect <<EOF &&
538 On branch master
539 +Your branch and '\''upstream'\'' have diverged,
540 +and have 1 and 2 different commits each, respectively.
541 + (use "git pull" to merge the remote branch into yours)
542 +
543 Changes to be committed:
544 (use "git reset HEAD <file>..." to unstage)
545
@@ -552,6 +599,10 @@ test_expect_success 'status -s (status.showUntrackedFiles all)' '
599 test_expect_success 'status with relative paths' '
600 cat >expect <<\EOF &&
601 On branch master
602 +Your branch and '\''upstream'\'' have diverged,
603 +and have 1 and 2 different commits each, respectively.
604 + (use "git pull" to merge the remote branch into yours)
605 +
606 Changes to be committed:
607 (use "git reset HEAD <file>..." to unstage)
608
@@ -617,6 +668,10 @@ test_expect_success 'setup unique colors' '
668 test_expect_success 'status with color.ui' '
669 cat >expect <<\EOF &&
670 On branch <GREEN>master<RESET>
671 +Your branch and '\''upstream'\'' have diverged,
672 +and have 1 and 2 different commits each, respectively.
673 + (use "git pull" to merge the remote branch into yours)
674 +
675 Changes to be committed:
676 (use "git reset HEAD <file>..." to unstage)
677
@@ -675,7 +730,7 @@ test_expect_success 'status -s with color.status' '
730 '
731
732 cat >expect <<\EOF
678 -## <GREEN>master<RESET>
733 +## <GREEN>master<RESET>...<RED>upstream<RESET> [ahead <GREEN>1<RESET>, behind <RED>2<RESET>]
734 <RED>M<RESET> dir1/modified
735 <GREEN>A<RESET> dir2/added
736 <BLUE>??<RESET> dir1/untracked
@@ -726,7 +781,7 @@ test_expect_success 'status --porcelain respects -b' '
781
782 git status --porcelain -b >output &&
783 {
729 - echo "## master" &&
784 + echo "## master...upstream [ahead 1, behind 2]" &&
785 cat expect
786 } >tmp &&
787 mv tmp expect &&
@@ -739,6 +794,10 @@ test_expect_success 'status --porcelain respects -b' '
794 test_expect_success 'status without relative paths' '
795 cat >expect <<\EOF &&
796 On branch master
797 +Your branch and '\''upstream'\'' have diverged,
798 +and have 1 and 2 different commits each, respectively.
799 + (use "git pull" to merge the remote branch into yours)
800 +
801 Changes to be committed:
802 (use "git reset HEAD <file>..." to unstage)
803
@@ -785,6 +844,10 @@ test_expect_success 'status -s without relative paths' '
844 test_expect_success 'dry-run of partial commit excluding new file in index' '
845 cat >expect <<EOF &&
846 On branch master
847 +Your branch and '\''upstream'\'' have diverged,
848 +and have 1 and 2 different commits each, respectively.
849 + (use "git pull" to merge the remote branch into yours)
850 +
851 Changes to be committed:
852 (use "git reset HEAD <file>..." to unstage)
853
@@ -825,6 +888,10 @@ test_expect_success 'setup status submodule summary' '
888 test_expect_success 'status submodule summary is disabled by default' '
889 cat >expect <<EOF &&
890 On branch master
891 +Your branch and '\''upstream'\'' have diverged,
892 +and have 1 and 2 different commits each, respectively.
893 + (use "git pull" to merge the remote branch into yours)
894 +
895 Changes to be committed:
896 (use "git reset HEAD <file>..." to unstage)
897
@@ -881,6 +948,10 @@ head=$(cd sm && git rev-parse --short=7 --verify HEAD)
948 test_expect_success 'status submodule summary' '
949 cat >expect <<EOF &&
950 On branch master
951 +Your branch and '\''upstream'\'' have diverged,
952 +and have 1 and 2 different commits each, respectively.
953 + (use "git pull" to merge the remote branch into yours)
954 +
955 Changes to be committed:
956 (use "git reset HEAD <file>..." to unstage)
957
@@ -939,6 +1010,10 @@ test_expect_success 'status -s submodule summary' '
1010 test_expect_success 'status submodule summary (clean submodule): commit' '
1011 cat >expect <<EOF &&
1012 On branch master
1013 +Your branch and '\''upstream'\'' have diverged,
1014 +and have 2 and 2 different commits each, respectively.
1015 + (use "git pull" to merge the remote branch into yours)
1016 +
1017 Changes not staged for commit:
1018 (use "git add <file>..." to update what will be committed)
1019 (use "git checkout -- <file>..." to discard changes in working directory)
@@ -985,6 +1060,10 @@ test_expect_success 'status -z implies porcelain' '
1060 test_expect_success 'commit --dry-run submodule summary (--amend)' '
1061 cat >expect <<EOF &&
1062 On branch master
1063 +Your branch and '\''upstream'\'' have diverged,
1064 +and have 2 and 2 different commits each, respectively.
1065 + (use "git pull" to merge the remote branch into yours)
1066 +
1067 Changes to be committed:
1068 (use "git reset HEAD^1 <file>..." to unstage)
1069
@@ -1038,6 +1117,10 @@ touch .gitmodules
1117 test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
1118 cat > expect << EOF &&
1119 On branch master
1120 +Your branch and '\''upstream'\'' have diverged,
1121 +and have 2 and 2 different commits each, respectively.
1122 + (use "git pull" to merge the remote branch into yours)
1123 +
1124 Changes to be committed:
1125 (use "git reset HEAD <file>..." to unstage)
1126
@@ -1146,6 +1229,10 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with modifie
1229 test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1230 cat > expect << EOF &&
1231 On branch master
1232 +Your branch and '\''upstream'\'' have diverged,
1233 +and have 2 and 2 different commits each, respectively.
1234 + (use "git pull" to merge the remote branch into yours)
1235 +
1236 Changes to be committed:
1237 (use "git reset HEAD <file>..." to unstage)
1238
@@ -1202,6 +1289,10 @@ head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --
1289 test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1290 cat > expect << EOF &&
1291 On branch master
1292 +Your branch and '\''upstream'\'' have diverged,
1293 +and have 2 and 2 different commits each, respectively.
1294 + (use "git pull" to merge the remote branch into yours)
1295 +
1296 Changes to be committed:
1297 (use "git reset HEAD <file>..." to unstage)
1298
@@ -1282,6 +1373,10 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary
1373
1374 cat > expect << EOF
1375 ; On branch master
1376 +; Your branch and 'upstream' have diverged,
1377 +; and have 2 and 2 different commits each, respectively.
1378 +; (use "git pull" to merge the remote branch into yours)
1379 +;
1380 ; Changes to be committed:
1381 ; (use "git reset HEAD <file>..." to unstage)
1382 ;
@@ -1329,6 +1424,10 @@ test_expect_success "status (core.commentchar with two chars with submodule summ
1424 test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1425 cat > expect << EOF &&
1426 On branch master
1427 +Your branch and '\''upstream'\'' have diverged,
1428 +and have 2 and 2 different commits each, respectively.
1429 + (use "git pull" to merge the remote branch into yours)
1430 +
1431 Changes not staged for commit:
1432 (use "git add <file>..." to update what will be committed)
1433 (use "git checkout -- <file>..." to discard changes in working directory)
@@ -1353,6 +1452,10 @@ EOF
1452 test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1453 cat > expect << EOF &&
1454 On branch master
1455 +Your branch and '\''upstream'\'' have diverged,
1456 +and have 2 and 2 different commits each, respectively.
1457 + (use "git pull" to merge the remote branch into yours)
1458 +
1459 Changes to be committed:
1460 (use "git reset HEAD <file>..." to unstage)
1461
@@ -1472,6 +1575,10 @@ test_expect_success 'git commit --dry-run will show a staged but ignored submodu
1575 git add sm &&
1576 cat >expect << EOF &&
1577 On branch master
1578 +Your branch and '\''upstream'\'' have diverged,
1579 +and have 2 and 2 different commits each, respectively.
1580 + (use "git pull" to merge the remote branch into yours)
1581 +
1582 Changes to be committed:
1583 (use "git reset HEAD <file>..." to unstage)
1584
wt-status.c
+1 -1
@@ -1002,7 +1002,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
1002 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
1003 comment_line_char);
1004 else
1005 - fputs("", s->fp);
1005 + fputs("\n", s->fp);
1006 }
1007
1008 static int has_unmerged(struct wt_status *s)