git-show: fix 'git show -s' to not add extra terminator after merge commit

When git show -s is called for merge commit it prints extra newline after any merge commit. This differs from output for commits with one parent. Fix it by more thorough checking that diff output is disabled. The code in question exists since commit 3969cf7db1. The additional newline is really needed for cases when patch is requested, test t4013-diff-various.sh contains cases which can demonstrate behavior when the condition is restricted further. Tests: Added merge commit to 'set up a bit of history' case in t7007-show.sh to cover the fix. Existing tests are updated to demonstrate the new behaviour. Earlier, the tests that used "git show -s --pretty=format:%s", even though "--pretty=format:%s" calls for item separator semantics and does not ask for the terminating newline after the last item, expected the output to end with such a newline. They were relying on the buggy behaviour. Use of "--format=%s", which is equivalent to "--pretty=tformat:%s" that asks for a terminating newline after each item, is a more realistic way to use the command. In the test 'merge log messages' the expected data is changed, because it was explicitly listing the extra newline. Also the msg.nologff and msg.nolognoff expected files are replaced by one msg.nolog, because they were diffing because of the bug, and now there should be no difference. Signed-off-by: Max Kirillov <max@max630.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Max Kirillov committed May 15, 2014 at 01:12 UTC ad2f7255b3e93dacd0982a946d30f6595dd8a805
4 files changed +15 -11
combine-diff.c
+2 -1
@@ -1331,7 +1331,8 @@ void diff_tree_combined(const unsigned char *sha1,
1331 if (show_log_first && i == 0) {
1332 show_log(rev);
1333
1334 - if (rev->verbose_header && opt->output_format)
1334 + if (rev->verbose_header && opt->output_format &&
1335 + opt->output_format != DIFF_FORMAT_NO_OUTPUT)
1336 printf("%s%c", diff_line_prefix(opt),
1337 opt->line_termination);
1338 }
t/t1507-rev-parse-upstream.sh
+1 -1
@@ -121,7 +121,7 @@ test_expect_success 'merge my-side@{u} records the correct name' '
121 git branch -D new ;# can fail but is ok
122 git branch -t new my-side@{u} &&
123 git merge -s ours new@{u} &&
124 - git show -s --pretty=format:%s >actual &&
124 + git show -s --pretty=tformat:%s >actual &&
125 echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&
126 test_cmp expect actual
127 )
t/t7007-show.sh
+7 -3
@@ -24,7 +24,8 @@ test_expect_success 'set up a bit of history' '
24 git tag -m "annotated tag" annotated &&
25 git checkout -b side HEAD^^ &&
26 test_commit side2 &&
27 - test_commit side3
27 + test_commit side3 &&
28 + test_merge merge main3
29 '
30
31 test_expect_success 'showing two commits' '
@@ -109,8 +110,11 @@ test_expect_success 'showing range' '
110 '
111
112 test_expect_success '-s suppresses diff' '
112 - echo main3 >expect &&
113 - git show -s --format=%s main3 >actual &&
113 + cat >expect <<-\EOF &&
114 + merge
115 + main3
116 + EOF
117 + git show -s --format=%s merge main3 >actual &&
118 test_cmp expect actual
119 '
120
t/t7600-merge.sh
+5 -6
@@ -57,11 +57,10 @@ create_merge_msgs () {
57 git log --no-merges ^HEAD c2 c3
58 } >squash.1-5-9 &&
59 : >msg.nologff &&
60 - echo >msg.nolognoff &&
60 + : >msg.nolognoff &&
61 {
62 echo "* tag 'c3':" &&
63 - echo " commit 3" &&
64 - echo
63 + echo " commit 3"
64 } >msg.log
65 }
66
@@ -71,7 +70,7 @@ verify_merge () {
70 git diff --exit-code &&
71 if test -n "$3"
72 then
74 - git show -s --pretty=format:%s HEAD >msg.act &&
73 + git show -s --pretty=tformat:%s HEAD >msg.act &&
74 test_cmp "$3" msg.act
75 fi
76 }
@@ -620,10 +619,10 @@ test_expect_success 'merge early part of c2' '
619 git tag c6 &&
620 git branch -f c5-branch c5 &&
621 git merge c5-branch~1 &&
623 - git show -s --pretty=format:%s HEAD >actual.branch &&
622 + git show -s --pretty=tformat:%s HEAD >actual.branch &&
623 git reset --keep HEAD^ &&
624 git merge c5~1 &&
626 - git show -s --pretty=format:%s HEAD >actual.tag &&
625 + git show -s --pretty=tformat:%s HEAD >actual.tag &&
626 test_cmp expected.branch actual.branch &&
627 test_cmp expected.tag actual.tag
628 '