3 test_description
='git show'
7 test_expect_success setup
'
8 echo hello world >foo &&
9 H=$(git hash-object -w foo) &&
10 git tag -a foo-tag -m "Tags $H" $H &&
11 HH=$(expr "$H" : "\(..\)") &&
12 H38=$(expr "$H" : "..\(.*\)") &&
13 rm -f .git/objects/$HH/$H38
16 test_expect_success
'showing a tag that point at a missing object' '
17 test_must_fail git --no-pager show foo-tag
20 test_expect_success
'set up a bit of history' '
24 git tag -m "annotated tag" annotated &&
25 git checkout -b side HEAD^^ &&
28 test_merge merge main3
31 test_expect_success
'showing two commits' '
33 commit $(git rev-parse main2)
34 commit $(git rev-parse main3)
36 git show main2 main3 >actual &&
37 grep ^commit actual >actual.filtered &&
38 test_cmp expect actual.filtered
41 test_expect_success
'showing a tree' '
42 cat >expected <<-EOF &&
47 git show main1: >actual &&
48 test_cmp expected actual
51 test_expect_success
'showing two trees' '
52 cat >expected <<-EOF &&
62 git show main1^{tree} main2^{tree} >actual &&
63 test_cmp expected actual
66 test_expect_success
'showing a trees is not recursive' '
67 git worktree add not-recursive main1 &&
68 mkdir not-recursive/a &&
69 test_commit -C not-recursive a/file &&
70 cat >expected <<-EOF &&
76 git -C not-recursive show HEAD^{tree} >actual &&
77 test_cmp expected actual
80 test_expect_success
'showing a range walks (linear)' '
82 commit $(git rev-parse main3)
83 commit $(git rev-parse main2)
85 git show main1..main3 >actual &&
86 grep ^commit actual >actual.filtered &&
87 test_cmp expect actual.filtered
90 test_expect_success
'showing a range walks (Y shape, ^ first)' '
92 commit $(git rev-parse main3)
93 commit $(git rev-parse main2)
95 git show ^side3 main3 >actual &&
96 grep ^commit actual >actual.filtered &&
97 test_cmp expect actual.filtered
100 test_expect_success
'showing a range walks (Y shape, ^ last)' '
101 cat >expect <<-EOF &&
102 commit $(git rev-parse main3)
103 commit $(git rev-parse main2)
105 git show main3 ^side3 >actual &&
106 grep ^commit actual >actual.filtered &&
107 test_cmp expect actual.filtered
110 test_expect_success
'showing with -N walks' '
111 cat >expect <<-EOF &&
112 commit $(git rev-parse main3)
113 commit $(git rev-parse main2)
115 git show -2 main3 >actual &&
116 grep ^commit actual >actual.filtered &&
117 test_cmp expect actual.filtered
120 test_expect_success
'showing annotated tag' '
121 cat >expect <<-EOF &&
123 commit $(git rev-parse annotated^{commit})
125 git show annotated >actual &&
126 grep -E "^(commit|tag)" actual >actual.filtered &&
127 test_cmp expect actual.filtered
130 test_expect_success
'showing annotated tag plus commit' '
131 cat >expect <<-EOF &&
133 commit $(git rev-parse annotated^{commit})
134 commit $(git rev-parse side3)
136 git show annotated side3 >actual &&
137 grep -E "^(commit|tag)" actual >actual.filtered &&
138 test_cmp expect actual.filtered
141 test_expect_success
'showing range' '
142 cat >expect <<-EOF &&
143 commit $(git rev-parse main3)
144 commit $(git rev-parse main2)
146 git show ^side3 annotated >actual &&
147 grep -E "^(commit|tag)" actual >actual.filtered &&
148 test_cmp expect actual.filtered
151 test_expect_success
'-s suppresses diff' '
152 cat >expect <<-\EOF &&
156 git show -s --format=%s merge main3 >actual &&
157 test_cmp expect actual
160 test_expect_success
'--quiet suppresses diff' '
161 echo main3 >expect &&
162 git show --quiet --format=%s main3 >actual &&
163 test_cmp expect actual
166 test_expect_success
'show --graph is forbidden' '
167 test_must_fail git show --graph HEAD