Merge branch 'bc/clone-empty-repo-via-protocol-v0'
[alt-git.git] / t / t7007-show.sh
blobf908a4d1abc5dc6608b4473937a614267013f3a2
1 #!/bin/sh
3 test_description='git show'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_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
17 test_expect_success 'showing a tag that point at a missing object' '
18 test_must_fail git --no-pager show foo-tag
21 test_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 &&
28 test_commit side3 &&
29 test_merge merge main3
32 test_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
42 test_expect_success 'showing a tree' '
43 cat >expected <<-EOF &&
44 tree main1:
46 main1.t
47 EOF
48 git show main1: >actual &&
49 test_cmp expected actual
52 test_expect_success 'showing two trees' '
53 cat >expected <<-EOF &&
54 tree main1^{tree}
56 main1.t
58 tree main2^{tree}
60 main1.t
61 main2.t
62 EOF
63 git show main1^{tree} main2^{tree} >actual &&
64 test_cmp expected actual
67 test_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}
75 main1.t
76 EOF
77 git -C not-recursive show HEAD^{tree} >actual &&
78 test_cmp expected actual
81 test_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
91 test_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
101 test_expect_success 'showing a range walks (Y shape, ^ last)' '
102 cat >expect <<-EOF &&
103 commit $(git rev-parse main3)
104 commit $(git rev-parse main2)
106 git show main3 ^side3 >actual &&
107 grep ^commit actual >actual.filtered &&
108 test_cmp expect actual.filtered
111 test_expect_success 'showing with -N walks' '
112 cat >expect <<-EOF &&
113 commit $(git rev-parse main3)
114 commit $(git rev-parse main2)
116 git show -2 main3 >actual &&
117 grep ^commit actual >actual.filtered &&
118 test_cmp expect actual.filtered
121 test_expect_success 'showing annotated tag' '
122 cat >expect <<-EOF &&
123 tag annotated
124 commit $(git rev-parse annotated^{commit})
126 git show annotated >actual &&
127 grep -E "^(commit|tag)" actual >actual.filtered &&
128 test_cmp expect actual.filtered
131 test_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)
137 git show annotated side3 >actual &&
138 grep -E "^(commit|tag)" actual >actual.filtered &&
139 test_cmp expect actual.filtered
142 test_expect_success 'showing range' '
143 cat >expect <<-EOF &&
144 commit $(git rev-parse main3)
145 commit $(git rev-parse main2)
147 git show ^side3 annotated >actual &&
148 grep -E "^(commit|tag)" actual >actual.filtered &&
149 test_cmp expect actual.filtered
152 test_expect_success '-s suppresses diff' '
153 cat >expect <<-\EOF &&
154 merge
155 main3
157 git show -s --format=%s merge main3 >actual &&
158 test_cmp expect actual
161 test_expect_success '--quiet suppresses diff' '
162 echo main3 >expect &&
163 git show --quiet --format=%s main3 >actual &&
164 test_cmp expect actual
167 test_expect_success 'show --graph is forbidden' '
168 test_must_fail git show --graph HEAD
171 test_done