Skip to content

Commit

Permalink
git-show: fix 'git show -s' to not add extra terminator after merge c…
Browse files Browse the repository at this point in the history
…ommit

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 3969cf7. 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>
  • Loading branch information
Max Kirillov authored and Junio C Hamano committed May 15, 2014
1 parent 7bbc4e8 commit ad2f725
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,8 @@ void diff_tree_combined(const unsigned char *sha1,
if (show_log_first && i == 0) {
show_log(rev);

if (rev->verbose_header && opt->output_format)
if (rev->verbose_header && opt->output_format &&
opt->output_format != DIFF_FORMAT_NO_OUTPUT)
printf("%s%c", diff_line_prefix(opt),
opt->line_termination);
}
Expand Down
2 changes: 1 addition & 1 deletion t/t1507-rev-parse-upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test_expect_success 'merge my-side@{u} records the correct name' '
git branch -D new ;# can fail but is ok
git branch -t new my-side@{u} &&
git merge -s ours new@{u} &&
git show -s --pretty=format:%s >actual &&
git show -s --pretty=tformat:%s >actual &&
echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&
test_cmp expect actual
)
Expand Down
10 changes: 7 additions & 3 deletions t/t7007-show.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ test_expect_success 'set up a bit of history' '
git tag -m "annotated tag" annotated &&
git checkout -b side HEAD^^ &&
test_commit side2 &&
test_commit side3
test_commit side3 &&
test_merge merge main3
'

test_expect_success 'showing two commits' '
Expand Down Expand Up @@ -109,8 +110,11 @@ test_expect_success 'showing range' '
'

test_expect_success '-s suppresses diff' '
echo main3 >expect &&
git show -s --format=%s main3 >actual &&
cat >expect <<-\EOF &&
merge
main3
EOF
git show -s --format=%s merge main3 >actual &&
test_cmp expect actual
'

Expand Down
11 changes: 5 additions & 6 deletions t/t7600-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ create_merge_msgs () {
git log --no-merges ^HEAD c2 c3
} >squash.1-5-9 &&
: >msg.nologff &&
echo >msg.nolognoff &&
: >msg.nolognoff &&
{
echo "* tag 'c3':" &&
echo " commit 3" &&
echo
echo " commit 3"
} >msg.log
}

Expand All @@ -71,7 +70,7 @@ verify_merge () {
git diff --exit-code &&
if test -n "$3"
then
git show -s --pretty=format:%s HEAD >msg.act &&
git show -s --pretty=tformat:%s HEAD >msg.act &&
test_cmp "$3" msg.act
fi
}
Expand Down Expand Up @@ -620,10 +619,10 @@ test_expect_success 'merge early part of c2' '
git tag c6 &&
git branch -f c5-branch c5 &&
git merge c5-branch~1 &&
git show -s --pretty=format:%s HEAD >actual.branch &&
git show -s --pretty=tformat:%s HEAD >actual.branch &&
git reset --keep HEAD^ &&
git merge c5~1 &&
git show -s --pretty=format:%s HEAD >actual.tag &&
git show -s --pretty=tformat:%s HEAD >actual.tag &&
test_cmp expected.branch actual.branch &&
test_cmp expected.tag actual.tag
'
Expand Down

0 comments on commit ad2f725

Please sign in to comment.