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 range walks (linear)' '
43 commit $(git rev-parse main3)
44 commit $(git rev-parse main2)
46 git show main1..main3 >actual &&
47 grep ^commit actual >actual.filtered &&
48 test_cmp expect actual.filtered
51 test_expect_success 'showing a range walks (Y shape, ^ first)' '
53 commit $(git rev-parse main3)
54 commit $(git rev-parse main2)
56 git show ^side3 main3 >actual &&
57 grep ^commit actual >actual.filtered &&
58 test_cmp expect actual.filtered
61 test_expect_success 'showing a range walks (Y shape, ^ last)' '
63 commit $(git rev-parse main3)
64 commit $(git rev-parse main2)
66 git show main3 ^side3 >actual &&
67 grep ^commit actual >actual.filtered &&
68 test_cmp expect actual.filtered
71 test_expect_success 'showing with -N walks' '
73 commit $(git rev-parse main3)
74 commit $(git rev-parse main2)
76 git show -2 main3 >actual &&
77 grep ^commit actual >actual.filtered &&
78 test_cmp expect actual.filtered
81 test_expect_success 'showing annotated tag' '
84 commit $(git rev-parse annotated^{commit})
86 git show annotated >actual &&
87 grep -E "^(commit|tag)" actual >actual.filtered &&
88 test_cmp expect actual.filtered
91 test_expect_success 'showing annotated tag plus commit' '
94 commit $(git rev-parse annotated^{commit})
95 commit $(git rev-parse side3)
97 git show annotated side3 >actual &&
98 grep -E "^(commit|tag)" actual >actual.filtered &&
99 test_cmp expect actual.filtered
102 test_expect_success 'showing range' '
103 cat >expect <<-EOF &&
104 commit $(git rev-parse main3)
105 commit $(git rev-parse main2)
107 git show ^side3 annotated >actual &&
108 grep -E "^(commit|tag)" actual >actual.filtered &&
109 test_cmp expect actual.filtered
112 test_expect_success '-s suppresses diff' '
113 cat >expect <<-\EOF &&
117 git show -s --format=%s merge main3 >actual &&
118 test_cmp expect actual
121 test_expect_success '--quiet suppresses diff' '
122 echo main3 >expect &&
123 git show --quiet --format=%s main3 >actual &&
124 test_cmp expect actual
127 test_expect_success 'show --graph is forbidden' '
128 test_must_fail git show --graph HEAD