Skip to content

Commit b0082b9

Browse files
trastgitster
authored andcommitted
Demonstrate git-show is broken with ranges
The logic of git-show has remained largely unchanged since around 5d7eeee (git-show: grok blobs, trees and tags, too, 2006-12-14): start a revision walker with no_walk=1, look at its pending objects and handle them one-by-one. For commits, this means stuffing them into a new queue all alone, and running the walker. Then Linus's f222abd (Make 'git show' more useful, 2009-07-13) came along and set no_walk=0 whenever the user specifies a range. Which appears to work fine, until you actually prod it hard enough, as the preceding commit shows: UNINTERESTING commits will be marked as such, but not walked further to propagate the marks. Demonstrate this with the main tests of this patch: 'showing a range walks (Y shape)'. The Y shape of history ensures that propagating the UNINTERESTING marks is necessary to correctly exclude the main1 commit. The only example I could find actually requires that the negative revisions are listed later, and in this scenario a dotted range actually works. However, it is easy to find examples in git.git where a dotted range is wrong, e.g. $ git show v1.7.0..v1.7.1 | grep ^commit | wc -l 1297 $ git rev-list v1.7.0..v1.7.1 | wc -l 702 While there, also test a few other things that are not covered so far: the -N way of triggering a range (added in 5853cae, DWIM 'git show -5' to 'git show --do-walk -5', 2010-06-01), and the interactions of tags, commits and ranges. Pointed out by Dr_Memory on #git. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9f5ef7 commit b0082b9

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

t/t7007-show.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,95 @@ test_expect_success 'showing a tag that point at a missing object' '
1717
test_must_fail git --no-pager show foo-tag
1818
'
1919

20+
test_expect_success 'set up a bit of history' '
21+
test_commit main1 &&
22+
test_commit main2 &&
23+
test_commit main3 &&
24+
git tag -m "annotated tag" annotated &&
25+
git checkout -b side HEAD^^ &&
26+
test_commit side2 &&
27+
test_commit side3
28+
'
29+
30+
test_expect_success 'showing two commits' '
31+
cat >expect <<-EOF &&
32+
commit $(git rev-parse main2)
33+
commit $(git rev-parse main3)
34+
EOF
35+
git show main2 main3 >actual &&
36+
grep ^commit actual >actual.filtered &&
37+
test_cmp expect actual.filtered
38+
'
39+
40+
test_expect_success 'showing a range walks (linear)' '
41+
cat >expect <<-EOF &&
42+
commit $(git rev-parse main3)
43+
commit $(git rev-parse main2)
44+
EOF
45+
git show main1..main3 >actual &&
46+
grep ^commit actual >actual.filtered &&
47+
test_cmp expect actual.filtered
48+
'
49+
50+
test_expect_success 'showing a range walks (Y shape, ^ first)' '
51+
cat >expect <<-EOF &&
52+
commit $(git rev-parse main3)
53+
commit $(git rev-parse main2)
54+
EOF
55+
git show ^side3 main3 >actual &&
56+
grep ^commit actual >actual.filtered &&
57+
test_cmp expect actual.filtered
58+
'
59+
60+
test_expect_failure 'showing a range walks (Y shape, ^ last)' '
61+
cat >expect <<-EOF &&
62+
commit $(git rev-parse main3)
63+
commit $(git rev-parse main2)
64+
EOF
65+
git show main3 ^side3 >actual &&
66+
grep ^commit actual >actual.filtered &&
67+
test_cmp expect actual.filtered
68+
'
69+
70+
test_expect_success 'showing with -N walks' '
71+
cat >expect <<-EOF &&
72+
commit $(git rev-parse main3)
73+
commit $(git rev-parse main2)
74+
EOF
75+
git show -2 main3 >actual &&
76+
grep ^commit actual >actual.filtered &&
77+
test_cmp expect actual.filtered
78+
'
79+
80+
test_expect_success 'showing annotated tag' '
81+
cat >expect <<-EOF &&
82+
tag annotated
83+
commit $(git rev-parse annotated^{commit})
84+
EOF
85+
git show annotated >actual &&
86+
grep -E "^(commit|tag)" actual >actual.filtered &&
87+
test_cmp expect actual.filtered
88+
'
89+
90+
test_expect_success 'showing annotated tag plus commit' '
91+
cat >expect <<-EOF &&
92+
tag annotated
93+
commit $(git rev-parse annotated^{commit})
94+
commit $(git rev-parse side3)
95+
EOF
96+
git show annotated side3 >actual &&
97+
grep -E "^(commit|tag)" actual >actual.filtered &&
98+
test_cmp expect actual.filtered
99+
'
100+
101+
test_expect_failure 'showing range' '
102+
cat >expect <<-EOF &&
103+
commit $(git rev-parse main3)
104+
commit $(git rev-parse main2)
105+
EOF
106+
git show ^side3 annotated >actual &&
107+
grep -E "^(commit|tag)" actual >actual.filtered &&
108+
test_cmp expect actual.filtered
109+
'
110+
20111
test_done

0 commit comments

Comments
 (0)