| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git show' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 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 |
| 14 | ' |
| 15 | |
| 16 | test_expect_success 'showing a tag that point at a missing object' ' |
| 17 | test_must_fail git --no-pager show foo-tag |
| 18 | ' |
| 19 | |
| 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 | test_merge merge main3 |
| 29 | ' |
| 30 | |
| 31 | test_expect_success 'showing two commits' ' |
| 32 | cat >expect <<-EOF && |
| 33 | commit $(git rev-parse main2) |
| 34 | commit $(git rev-parse main3) |
| 35 | EOF |
| 36 | git show main2 main3 >actual && |
| 37 | grep ^commit actual >actual.filtered && |
| 38 | test_cmp expect actual.filtered |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'showing a tree' ' |
| 42 | cat >expected <<-EOF && |
| 43 | tree main1: |
| 44 | |
| 45 | main1.t |
| 46 | EOF |
| 47 | git show main1: >actual && |
| 48 | test_cmp expected actual |
| 49 | ' |
| 50 | |
| 51 | test_expect_success 'showing two trees' ' |
| 52 | cat >expected <<-EOF && |
| 53 | tree main1^{tree} |
| 54 | |
| 55 | main1.t |
| 56 | |
| 57 | tree main2^{tree} |
| 58 | |
| 59 | main1.t |
| 60 | main2.t |
| 61 | EOF |
| 62 | git show main1^{tree} main2^{tree} >actual && |
| 63 | test_cmp expected actual |
| 64 | ' |
| 65 | |
| 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 && |
| 71 | tree HEAD^{tree} |
| 72 | |
| 73 | a/ |
| 74 | main1.t |
| 75 | EOF |
| 76 | git -C not-recursive show HEAD^{tree} >actual && |
| 77 | test_cmp expected actual |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'showing a range walks (linear)' ' |
| 81 | cat >expect <<-EOF && |
| 82 | commit $(git rev-parse main3) |
| 83 | commit $(git rev-parse main2) |
| 84 | EOF |
| 85 | git show main1..main3 >actual && |
| 86 | grep ^commit actual >actual.filtered && |
| 87 | test_cmp expect actual.filtered |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'showing a range walks (Y shape, ^ first)' ' |
| 91 | cat >expect <<-EOF && |
| 92 | commit $(git rev-parse main3) |
| 93 | commit $(git rev-parse main2) |
| 94 | EOF |
| 95 | git show ^side3 main3 >actual && |
| 96 | grep ^commit actual >actual.filtered && |
| 97 | test_cmp expect actual.filtered |
| 98 | ' |
| 99 | |
| 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) |
| 104 | EOF |
| 105 | git show main3 ^side3 >actual && |
| 106 | grep ^commit actual >actual.filtered && |
| 107 | test_cmp expect actual.filtered |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'showing with -N walks' ' |
| 111 | cat >expect <<-EOF && |
| 112 | commit $(git rev-parse main3) |
| 113 | commit $(git rev-parse main2) |
| 114 | EOF |
| 115 | git show -2 main3 >actual && |
| 116 | grep ^commit actual >actual.filtered && |
| 117 | test_cmp expect actual.filtered |
| 118 | ' |
| 119 | |
| 120 | test_expect_success 'showing annotated tag' ' |
| 121 | cat >expect <<-EOF && |
| 122 | tag annotated |
| 123 | commit $(git rev-parse annotated^{commit}) |
| 124 | EOF |
| 125 | git show annotated >actual && |
| 126 | grep -E "^(commit|tag)" actual >actual.filtered && |
| 127 | test_cmp expect actual.filtered |
| 128 | ' |
| 129 | |
| 130 | test_expect_success 'showing annotated tag plus commit' ' |
| 131 | cat >expect <<-EOF && |
| 132 | tag annotated |
| 133 | commit $(git rev-parse annotated^{commit}) |
| 134 | commit $(git rev-parse side3) |
| 135 | EOF |
| 136 | git show annotated side3 >actual && |
| 137 | grep -E "^(commit|tag)" actual >actual.filtered && |
| 138 | test_cmp expect actual.filtered |
| 139 | ' |
| 140 | |
| 141 | test_expect_success 'showing range' ' |
| 142 | cat >expect <<-EOF && |
| 143 | commit $(git rev-parse main3) |
| 144 | commit $(git rev-parse main2) |
| 145 | EOF |
| 146 | git show ^side3 annotated >actual && |
| 147 | grep -E "^(commit|tag)" actual >actual.filtered && |
| 148 | test_cmp expect actual.filtered |
| 149 | ' |
| 150 | |
| 151 | test_expect_success '-s suppresses diff' ' |
| 152 | cat >expect <<-\EOF && |
| 153 | merge |
| 154 | main3 |
| 155 | EOF |
| 156 | git show -s --format=%s merge main3 >actual && |
| 157 | test_cmp expect actual |
| 158 | ' |
| 159 | |
| 160 | test_expect_success '--quiet suppresses diff' ' |
| 161 | echo main3 >expect && |
| 162 | git show --quiet --format=%s main3 >actual && |
| 163 | test_cmp expect actual |
| 164 | ' |
| 165 | |
| 166 | test_expect_success 'show --graph is forbidden' ' |
| 167 | test_must_fail git show --graph HEAD |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'show unmerged index' ' |
| 171 | git reset --hard && |
| 172 | |
| 173 | git switch -C base && |
| 174 | echo "base" >conflicting && |
| 175 | git add conflicting && |
| 176 | git commit -m "base" && |
| 177 | |
| 178 | git branch hello && |
| 179 | git branch goodbye && |
| 180 | |
| 181 | git switch hello && |
| 182 | echo "hello" >conflicting && |
| 183 | git commit -am "hello" && |
| 184 | |
| 185 | git switch goodbye && |
| 186 | echo "goodbye" >conflicting && |
| 187 | git commit -am "goodbye" && |
| 188 | |
| 189 | git switch hello && |
| 190 | test_must_fail git merge goodbye && |
| 191 | git show --merge HEAD |
| 192 | ' |
| 193 | |
| 194 | test_done |