mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
![Max Kirillov](/assets/img/avatar_default.png)
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>
128 lines
3 KiB
Bash
Executable file
128 lines
3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='git show'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
echo hello world >foo &&
|
|
H=$(git hash-object -w foo) &&
|
|
git tag -a foo-tag -m "Tags $H" $H &&
|
|
HH=$(expr "$H" : "\(..\)") &&
|
|
H38=$(expr "$H" : "..\(.*\)") &&
|
|
rm -f .git/objects/$HH/$H38
|
|
'
|
|
|
|
test_expect_success 'showing a tag that point at a missing object' '
|
|
test_must_fail git --no-pager show foo-tag
|
|
'
|
|
|
|
test_expect_success 'set up a bit of history' '
|
|
test_commit main1 &&
|
|
test_commit main2 &&
|
|
test_commit main3 &&
|
|
git tag -m "annotated tag" annotated &&
|
|
git checkout -b side HEAD^^ &&
|
|
test_commit side2 &&
|
|
test_commit side3 &&
|
|
test_merge merge main3
|
|
'
|
|
|
|
test_expect_success 'showing two commits' '
|
|
cat >expect <<-EOF &&
|
|
commit $(git rev-parse main2)
|
|
commit $(git rev-parse main3)
|
|
EOF
|
|
git show main2 main3 >actual &&
|
|
grep ^commit actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing a range walks (linear)' '
|
|
cat >expect <<-EOF &&
|
|
commit $(git rev-parse main3)
|
|
commit $(git rev-parse main2)
|
|
EOF
|
|
git show main1..main3 >actual &&
|
|
grep ^commit actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing a range walks (Y shape, ^ first)' '
|
|
cat >expect <<-EOF &&
|
|
commit $(git rev-parse main3)
|
|
commit $(git rev-parse main2)
|
|
EOF
|
|
git show ^side3 main3 >actual &&
|
|
grep ^commit actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing a range walks (Y shape, ^ last)' '
|
|
cat >expect <<-EOF &&
|
|
commit $(git rev-parse main3)
|
|
commit $(git rev-parse main2)
|
|
EOF
|
|
git show main3 ^side3 >actual &&
|
|
grep ^commit actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing with -N walks' '
|
|
cat >expect <<-EOF &&
|
|
commit $(git rev-parse main3)
|
|
commit $(git rev-parse main2)
|
|
EOF
|
|
git show -2 main3 >actual &&
|
|
grep ^commit actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing annotated tag' '
|
|
cat >expect <<-EOF &&
|
|
tag annotated
|
|
commit $(git rev-parse annotated^{commit})
|
|
EOF
|
|
git show annotated >actual &&
|
|
grep -E "^(commit|tag)" actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing annotated tag plus commit' '
|
|
cat >expect <<-EOF &&
|
|
tag annotated
|
|
commit $(git rev-parse annotated^{commit})
|
|
commit $(git rev-parse side3)
|
|
EOF
|
|
git show annotated side3 >actual &&
|
|
grep -E "^(commit|tag)" actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success 'showing range' '
|
|
cat >expect <<-EOF &&
|
|
commit $(git rev-parse main3)
|
|
commit $(git rev-parse main2)
|
|
EOF
|
|
git show ^side3 annotated >actual &&
|
|
grep -E "^(commit|tag)" actual >actual.filtered &&
|
|
test_cmp expect actual.filtered
|
|
'
|
|
|
|
test_expect_success '-s suppresses diff' '
|
|
cat >expect <<-\EOF &&
|
|
merge
|
|
main3
|
|
EOF
|
|
git show -s --format=%s merge main3 >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success '--quiet suppresses diff' '
|
|
echo main3 >expect &&
|
|
git show --quiet --format=%s main3 >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|