{"thread":{"id":"45818","subject":"[PATCH] status: fix missing newline when comment chars are disabled","startedAt":"2017-04-27T09:01:18Z","lastAt":"2017-04-27T09:01:18Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"318061","messageId":"20170427090105.vaodugbqdaxunoin@sigill.intra.peff.net","threadId":"45818","inReplyTo":null,"subject":"[PATCH] status: fix missing newline when comment chars are disabled","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-04-27T09:01:05Z","receivedAt":"2017-04-27T09:01:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When git-status shows tracking data for the current branch\nin the long format, we try to end the stanza with a blank\nline. When status.displayCommentPrefix is true, we call\ncolor_fprintf_ln() to do so. But when it's false, we call\nthe enigmatic:\n\n  fputs(\"\", s->fp);\n\nwhich does nothing at all! This is a bug from 7d7d68022\n(silence a bunch of format-zero-length warnings,\n2014-05-04). Prior to that, we called fprintf_ln() with an\nempty string. Switching to fputs() meant we needed to\ninclude the \"newline in the string, but we didn't.\n\nSo you see:\n\n  On branch jk/status-tracking-newline\n  Your branch is ahead of 'origin/master' by 1 commit.\n  Changes not staged for commit:\n          modified:  foo\n\n  Untracked files:\n     bar\n\nwhereas there should be a blank line before the \"Changes not\nstaged\" line.\n\nThe fix itself is a one-liner. But we never noticed this\nbug because t7508 doesn't exercise the ahead/behind code at\nall.  So let's configure an upstream during the initial\nsetup, which means that the code will be exercised as part\nof all of the various invocations in that script. This makes\nthe diff rather noisy, but should give us good coverage.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThe no-comment view is the default, so this has been broken\nfor basically everyone for 2 years. And nobody complained.\nSo perhaps people really prefer it? Or perhaps they just\ndidn't notice. I certainly didn't, but now that I know about\nit, the squished view is intolerable. :)\n\n t/t7508-status.sh | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++--\n wt-status.c       |   2 +-\n 2 files changed, 112 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex fb00e6d9b..a000ed4e7 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -32,6 +32,17 @@ test_expect_success 'commit -h in broken repository' '\n \ttest_i18ngrep \"[Uu]sage\" broken/usage\n '\n \n+test_expect_success 'create upstream branch' '\n+\tgit checkout -b upstream &&\n+\ttest_commit upstream1 &&\n+\ttest_commit upstream2 &&\n+\t# leave the first commit on master as root because several\n+\t# tests depend on this case; for our upstream we only\n+\t# care about commit counts anyway, so a totally divergent\n+\t# history is OK\n+\tgit checkout --orphan master\n+'\n+\n test_expect_success 'setup' '\n \t: >tracked &&\n \t: >modified &&\n@@ -53,7 +64,9 @@ test_expect_success 'setup' '\n \techo 1 >dir1/modified &&\n \techo 2 >dir2/modified &&\n \techo 3 >dir2/added &&\n-\tgit add dir2/added\n+\tgit add dir2/added &&\n+\n+\tgit branch --set-upstream-to=upstream\n '\n \n test_expect_success 'status (1)' '\n@@ -75,6 +88,10 @@ EOF\n test_expect_success 'status --column' '\n \tcat >expect <<\\EOF &&\n # On branch master\n+# Your branch and '\\''upstream'\\'' have diverged,\n+# and have 1 and 2 different commits each, respectively.\n+#   (use \"git pull\" to merge the remote branch into yours)\n+#\n # Changes to be committed:\n #   (use \"git reset HEAD <file>...\" to unstage)\n #\n@@ -105,6 +122,10 @@ test_expect_success 'status --column status.displayCommentPrefix=false' '\n \n cat >expect <<\\EOF\n # On branch master\n+# Your branch and 'upstream' have diverged,\n+# and have 1 and 2 different commits each, respectively.\n+#   (use \"git pull\" to merge the remote branch into yours)\n+#\n # Changes to be committed:\n #   (use \"git reset HEAD <file>...\" to unstage)\n #\n@@ -178,6 +199,9 @@ test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_\n \n cat >expect <<\\EOF\n On branch master\n+Your branch and 'upstream' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+\n Changes to be committed:\n \tnew file:   dir2/added\n \n@@ -248,6 +272,10 @@ test_expect_success 'status with gitignore' '\n \n \tcat >expect <<\\EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -313,6 +341,10 @@ test_expect_success 'status with gitignore (nothing untracked)' '\n \n \tcat >expect <<\\EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -348,7 +380,7 @@ output*\n EOF\n \n cat >expect <<\\EOF\n-## master\n+## master...upstream [ahead 1, behind 2]\n  M dir1/modified\n A  dir2/added\n ?? dir1/untracked\n@@ -382,6 +414,10 @@ test_expect_success 'setup dir3' '\n test_expect_success 'status -uno' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -408,6 +444,9 @@ test_expect_success 'status (status.showUntrackedFiles no)' '\n test_expect_success 'status -uno (advice.statusHints false)' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+\n Changes to be committed:\n \tnew file:   dir2/added\n \n@@ -439,6 +478,10 @@ test_expect_success 'status -s (status.showUntrackedFiles no)' '\n test_expect_success 'status -unormal' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -493,6 +536,10 @@ test_expect_success 'status -s (status.showUntrackedFiles normal)' '\n test_expect_success 'status -uall' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -552,6 +599,10 @@ test_expect_success 'status -s (status.showUntrackedFiles all)' '\n test_expect_success 'status with relative paths' '\n \tcat >expect <<\\EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -617,6 +668,10 @@ test_expect_success 'setup unique colors' '\n test_expect_success 'status with color.ui' '\n \tcat >expect <<\\EOF &&\n On branch <GREEN>master<RESET>\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -675,7 +730,7 @@ test_expect_success 'status -s with color.status' '\n '\n \n cat >expect <<\\EOF\n-## <GREEN>master<RESET>\n+## <GREEN>master<RESET>...<RED>upstream<RESET> [ahead <GREEN>1<RESET>, behind <RED>2<RESET>]\n  <RED>M<RESET> dir1/modified\n <GREEN>A<RESET>  dir2/added\n <BLUE>??<RESET> dir1/untracked\n@@ -726,7 +781,7 @@ test_expect_success 'status --porcelain respects -b' '\n \n \tgit status --porcelain -b >output &&\n \t{\n-\t\techo \"## master\" &&\n+\t\techo \"## master...upstream [ahead 1, behind 2]\" &&\n \t\tcat expect\n \t} >tmp &&\n \tmv tmp expect &&\n@@ -739,6 +794,10 @@ test_expect_success 'status --porcelain respects -b' '\n test_expect_success 'status without relative paths' '\n \tcat >expect <<\\EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -785,6 +844,10 @@ test_expect_success 'status -s without relative paths' '\n test_expect_success 'dry-run of partial commit excluding new file in index' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -825,6 +888,10 @@ test_expect_success 'setup status submodule summary' '\n test_expect_success 'status submodule summary is disabled by default' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -881,6 +948,10 @@ head=$(cd sm && git rev-parse --short=7 --verify HEAD)\n test_expect_success 'status submodule summary' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 1 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -939,6 +1010,10 @@ test_expect_success 'status -s submodule summary' '\n test_expect_success 'status submodule summary (clean submodule): commit' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes not staged for commit:\n   (use \"git add <file>...\" to update what will be committed)\n   (use \"git checkout -- <file>...\" to discard changes in working directory)\n@@ -985,6 +1060,10 @@ test_expect_success 'status -z implies porcelain' '\n test_expect_success 'commit --dry-run submodule summary (--amend)' '\n \tcat >expect <<EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD^1 <file>...\" to unstage)\n \n@@ -1038,6 +1117,10 @@ touch .gitmodules\n test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '\n \tcat > expect << EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -1146,6 +1229,10 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with modifie\n test_expect_success \"--ignore-submodules=untracked doesn't suppress submodules with modified content\" '\n \tcat > expect << EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -1202,6 +1289,10 @@ head2=$(cd sm && git commit -q -m \"2nd commit\" foo && git rev-parse --short=7 --\n test_expect_success \"--ignore-submodules=untracked doesn't suppress submodule summary\" '\n \tcat > expect << EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -1282,6 +1373,10 @@ test_expect_success \".git/config ignore=dirty doesn't suppress submodule summary\n \n cat > expect << EOF\n ; On branch master\n+; Your branch and 'upstream' have diverged,\n+; and have 2 and 2 different commits each, respectively.\n+;   (use \"git pull\" to merge the remote branch into yours)\n+;\n ; Changes to be committed:\n ;   (use \"git reset HEAD <file>...\" to unstage)\n ;\n@@ -1329,6 +1424,10 @@ test_expect_success \"status (core.commentchar with two chars with submodule summ\n test_expect_success \"--ignore-submodules=all suppresses submodule summary\" '\n \tcat > expect << EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes not staged for commit:\n   (use \"git add <file>...\" to update what will be committed)\n   (use \"git checkout -- <file>...\" to discard changes in working directory)\n@@ -1353,6 +1452,10 @@ EOF\n test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '\n \tcat > expect << EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \n@@ -1472,6 +1575,10 @@ test_expect_success 'git commit --dry-run will show a staged but ignored submodu\n \tgit add sm &&\n \tcat >expect << EOF &&\n On branch master\n+Your branch and '\\''upstream'\\'' have diverged,\n+and have 2 and 2 different commits each, respectively.\n+  (use \"git pull\" to merge the remote branch into yours)\n+\n Changes to be committed:\n   (use \"git reset HEAD <file>...\" to unstage)\n \ndiff --git a/wt-status.c b/wt-status.c\nindex 037548496..b7ade902f 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1002,7 +1002,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)\n \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"%c\",\n \t\t\t\t comment_line_char);\n \telse\n-\t\tfputs(\"\", s->fp);\n+\t\tfputs(\"\\n\", s->fp);\n }\n \n static int has_unmerged(struct wt_status *s)\n-- \n2.13.0.rc1.388.gcf562aed8\n"}]}