]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7007-show.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t7007-show.sh
CommitLineData
d2dadfe8
JH
1#!/bin/sh
2
3test_description='git show'
4
055e57b7 5TEST_PASSES_SANITIZE_LEAK=true
d2dadfe8
JH
6. ./test-lib.sh
7
8test_expect_success setup '
9 echo hello world >foo &&
10 H=$(git hash-object -w foo) &&
11 git tag -a foo-tag -m "Tags $H" $H &&
12 HH=$(expr "$H" : "\(..\)") &&
13 H38=$(expr "$H" : "..\(.*\)") &&
14 rm -f .git/objects/$HH/$H38
15'
16
17test_expect_success 'showing a tag that point at a missing object' '
18 test_must_fail git --no-pager show foo-tag
19'
20
b0082b9d
TR
21test_expect_success 'set up a bit of history' '
22 test_commit main1 &&
23 test_commit main2 &&
24 test_commit main3 &&
25 git tag -m "annotated tag" annotated &&
26 git checkout -b side HEAD^^ &&
27 test_commit side2 &&
ad2f7255
MK
28 test_commit side3 &&
29 test_merge merge main3
b0082b9d
TR
30'
31
32test_expect_success 'showing two commits' '
33 cat >expect <<-EOF &&
34 commit $(git rev-parse main2)
35 commit $(git rev-parse main3)
36 EOF
37 git show main2 main3 >actual &&
38 grep ^commit actual >actual.filtered &&
39 test_cmp expect actual.filtered
40'
41
dcc0a86f
ÆAB
42test_expect_success 'showing a tree' '
43 cat >expected <<-EOF &&
44 tree main1:
45
46 main1.t
47 EOF
48 git show main1: >actual &&
49 test_cmp expected actual
50'
51
52test_expect_success 'showing two trees' '
53 cat >expected <<-EOF &&
54 tree main1^{tree}
55
56 main1.t
57
58 tree main2^{tree}
59
60 main1.t
61 main2.t
62 EOF
63 git show main1^{tree} main2^{tree} >actual &&
64 test_cmp expected actual
65'
66
67test_expect_success 'showing a trees is not recursive' '
68 git worktree add not-recursive main1 &&
69 mkdir not-recursive/a &&
70 test_commit -C not-recursive a/file &&
71 cat >expected <<-EOF &&
72 tree HEAD^{tree}
73
74 a/
75 main1.t
76 EOF
77 git -C not-recursive show HEAD^{tree} >actual &&
78 test_cmp expected actual
79'
80
b0082b9d
TR
81test_expect_success 'showing a range walks (linear)' '
82 cat >expect <<-EOF &&
83 commit $(git rev-parse main3)
84 commit $(git rev-parse main2)
85 EOF
86 git show main1..main3 >actual &&
87 grep ^commit actual >actual.filtered &&
88 test_cmp expect actual.filtered
89'
90
91test_expect_success 'showing a range walks (Y shape, ^ first)' '
92 cat >expect <<-EOF &&
93 commit $(git rev-parse main3)
94 commit $(git rev-parse main2)
95 EOF
96 git show ^side3 main3 >actual &&
97 grep ^commit actual >actual.filtered &&
98 test_cmp expect actual.filtered
99'
100
c5941f1a 101test_expect_success 'showing a range walks (Y shape, ^ last)' '
b0082b9d
TR
102 cat >expect <<-EOF &&
103 commit $(git rev-parse main3)
104 commit $(git rev-parse main2)
105 EOF
106 git show main3 ^side3 >actual &&
107 grep ^commit actual >actual.filtered &&
108 test_cmp expect actual.filtered
109'
110
111test_expect_success 'showing with -N walks' '
112 cat >expect <<-EOF &&
113 commit $(git rev-parse main3)
114 commit $(git rev-parse main2)
115 EOF
116 git show -2 main3 >actual &&
117 grep ^commit actual >actual.filtered &&
118 test_cmp expect actual.filtered
119'
120
121test_expect_success 'showing annotated tag' '
122 cat >expect <<-EOF &&
123 tag annotated
124 commit $(git rev-parse annotated^{commit})
125 EOF
126 git show annotated >actual &&
127 grep -E "^(commit|tag)" actual >actual.filtered &&
128 test_cmp expect actual.filtered
129'
130
131test_expect_success 'showing annotated tag plus commit' '
132 cat >expect <<-EOF &&
133 tag annotated
134 commit $(git rev-parse annotated^{commit})
135 commit $(git rev-parse side3)
136 EOF
137 git show annotated side3 >actual &&
138 grep -E "^(commit|tag)" actual >actual.filtered &&
139 test_cmp expect actual.filtered
140'
141
c5941f1a 142test_expect_success 'showing range' '
b0082b9d
TR
143 cat >expect <<-EOF &&
144 commit $(git rev-parse main3)
145 commit $(git rev-parse main2)
146 EOF
147 git show ^side3 annotated >actual &&
148 grep -E "^(commit|tag)" actual >actual.filtered &&
149 test_cmp expect actual.filtered
150'
151
f9c75d85 152test_expect_success '-s suppresses diff' '
ad2f7255
MK
153 cat >expect <<-\EOF &&
154 merge
155 main3
156 EOF
157 git show -s --format=%s merge main3 >actual &&
f9c75d85
JK
158 test_cmp expect actual
159'
160
161test_expect_success '--quiet suppresses diff' '
162 echo main3 >expect &&
163 git show --quiet --format=%s main3 >actual &&
164 test_cmp expect actual
165'
166
695985f4
DJ
167test_expect_success 'show --graph is forbidden' '
168 test_must_fail git show --graph HEAD
169'
170
d2dadfe8 171test_done