1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-16 22:14:53 +01:00
git/t/t7007-show.sh
Jeff King f9c75d858d log: fix --quiet synonym for -s
Originally the "--quiet" option was parsed by the
diff-option parser into the internal QUICK option. This had
the effect of silencing diff output from the log (which was
not intended, but happened to work and people started to
use it). But it also had other odd side effects at the diff
level (for example, it would suppress the second commit in
"git show A B").

To fix this, commit 1c40c36 converted log to parse-options
and handled the "quiet" option separately, not passing it
on to the diff code. However, it simply ignored the option,
which was a regression for people using it as a synonym for
"-s". Commit 01771a8 then fixed that by interpreting the
option to add DIFF_FORMAT_NO_OUTPUT to the list of output
formats.

However, that commit did not fix it in all cases. It sets
the flag after setup_revisions is called. Naively, this
makes sense because you would expect the setup_revisions
parser to overwrite our output format flag if "-p" or
another output format flag is seen.

However, that is not how the NO_OUTPUT flag works. We
actually store it in the bit-field as just another format.
At the end of setup_revisions, we call diff_setup_done,
which post-processes the bitfield and clears any other
formats if we have set NO_OUTPUT. By setting the flag after
setup_revisions is done, diff_setup_done does not have a
chance to make this tweak, and we end up with other format
options still set.

As a result, the flag would have no effect in "git log -p
--quiet" or "git show --quiet".  Fix it by setting the
format flag before the call to setup_revisions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-28 15:37:29 -07:00

123 lines
2.9 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_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' '
echo main3 >expect &&
git show -s --format=%s 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