| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Johannes Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='Test git rev-parse with different parent options' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
| 12 | . ./test-lib.sh |
| 13 | |
| 14 | test_cmp_rev_output () { |
| 15 | git rev-parse --verify "$1" >expect && |
| 16 | eval "$2" >actual && |
| 17 | test_cmp expect actual |
| 18 | } |
| 19 | |
| 20 | test_expect_success 'setup' ' |
| 21 | test_commit start && |
| 22 | test_commit second && |
| 23 | git checkout --orphan tmp && |
| 24 | test_commit start2 && |
| 25 | git checkout main && |
| 26 | git merge -m next --allow-unrelated-histories start2 && |
| 27 | test_commit final && |
| 28 | |
| 29 | mkdir .git/info && |
| 30 | test_seq 40 | |
| 31 | while read i |
| 32 | do |
| 33 | git checkout --orphan "b$i" && |
| 34 | test_tick && |
| 35 | git commit --allow-empty -m "$i" && |
| 36 | commit=$(git rev-parse --verify HEAD) && |
| 37 | printf "$commit " >>.git/info/grafts || return 1 |
| 38 | done |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'start is valid' ' |
| 42 | git rev-parse start >actual && |
| 43 | test_grep "^$OID_REGEX$" actual |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'start^0' ' |
| 47 | test_cmp_rev_output tags/start "git rev-parse start^0" |
| 48 | ' |
| 49 | |
| 50 | test_expect_success 'start^1 not valid' ' |
| 51 | test_must_fail git rev-parse --verify start^1 |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'second^1 = second^' ' |
| 55 | test_cmp_rev_output second^ "git rev-parse second^1" |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'final^1^1^1' ' |
| 59 | test_cmp_rev_output start "git rev-parse final^1^1^1" |
| 60 | ' |
| 61 | |
| 62 | test_expect_success 'final^1^1^1 = final^^^' ' |
| 63 | test_cmp_rev_output final^^^ "git rev-parse final^1^1^1" |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'final^1^2' ' |
| 67 | test_cmp_rev_output start2 "git rev-parse final^1^2" |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'final^1^2 != final^1^1' ' |
| 71 | test $(git rev-parse final^1^2) != $(git rev-parse final^1^1) |
| 72 | ' |
| 73 | |
| 74 | test_expect_success 'final^1^3 not valid' ' |
| 75 | test_must_fail git rev-parse --verify final^1^3 |
| 76 | ' |
| 77 | |
| 78 | test_expect_success '--verify start2^1' ' |
| 79 | test_must_fail git rev-parse --verify start2^1 |
| 80 | ' |
| 81 | |
| 82 | test_expect_success '--verify start2^0' ' |
| 83 | git rev-parse --verify start2^0 |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'final^1^@ = final^1^1 final^1^2' ' |
| 87 | git rev-parse final^1^1 final^1^2 >expect && |
| 88 | git rev-parse final^1^@ >actual && |
| 89 | test_cmp expect actual |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'symbolic final^1^@ = final^1^1 final^1^2' ' |
| 93 | git rev-parse --symbolic final^1^1 final^1^2 >expect && |
| 94 | git rev-parse --symbolic final^1^@ >actual && |
| 95 | test_cmp expect actual |
| 96 | ' |
| 97 | |
| 98 | test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' ' |
| 99 | git rev-parse final^1 ^final^1^1 ^final^1^2 >expect && |
| 100 | git rev-parse final^1^! >actual && |
| 101 | test_cmp expect actual |
| 102 | ' |
| 103 | |
| 104 | test_expect_success 'symbolic final^1^! = final^1 ^final^1^1 ^final^1^2' ' |
| 105 | git rev-parse --symbolic final^1 ^final^1^1 ^final^1^2 >expect && |
| 106 | git rev-parse --symbolic final^1^! >actual && |
| 107 | test_cmp expect actual |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'large graft octopus' ' |
| 111 | test_cmp_rev_output b31 "git rev-parse --verify b1^30" |
| 112 | ' |
| 113 | |
| 114 | test_expect_success 'repack for next test' ' |
| 115 | git repack -a -d |
| 116 | ' |
| 117 | |
| 118 | test_expect_success 'short SHA-1 works' ' |
| 119 | start=$(git rev-parse --verify start) && |
| 120 | test_cmp_rev_output start "git rev-parse ${start%?}" |
| 121 | ' |
| 122 | |
| 123 | # rev^- tests; we can use a simpler setup for these |
| 124 | |
| 125 | test_expect_success 'setup for rev^- tests' ' |
| 126 | test_commit one && |
| 127 | test_commit two && |
| 128 | test_commit three && |
| 129 | |
| 130 | # Merge in a branch for testing rev^- |
| 131 | git checkout -b branch && |
| 132 | git checkout HEAD^^ && |
| 133 | git merge -m merge --no-edit --no-ff branch && |
| 134 | git checkout -b merge |
| 135 | ' |
| 136 | |
| 137 | # The merged branch has 2 commits + the merge |
| 138 | test_expect_success 'rev-list --count merge^- = merge^..merge' ' |
| 139 | git rev-list --count merge^..merge >expect && |
| 140 | echo 3 >actual && |
| 141 | test_cmp expect actual |
| 142 | ' |
| 143 | |
| 144 | # All rev^- rev-parse tests |
| 145 | |
| 146 | test_expect_success 'rev-parse merge^- = merge^..merge' ' |
| 147 | git rev-parse merge^..merge >expect && |
| 148 | git rev-parse merge^- >actual && |
| 149 | test_cmp expect actual |
| 150 | ' |
| 151 | |
| 152 | test_expect_success 'rev-parse merge^-1 = merge^..merge' ' |
| 153 | git rev-parse merge^1..merge >expect && |
| 154 | git rev-parse merge^-1 >actual && |
| 155 | test_cmp expect actual |
| 156 | ' |
| 157 | |
| 158 | test_expect_success 'rev-parse merge^-2 = merge^2..merge' ' |
| 159 | git rev-parse merge^2..merge >expect && |
| 160 | git rev-parse merge^-2 >actual && |
| 161 | test_cmp expect actual |
| 162 | ' |
| 163 | |
| 164 | test_expect_success 'symbolic merge^-1 = merge^1..merge' ' |
| 165 | git rev-parse --symbolic merge^1..merge >expect && |
| 166 | git rev-parse --symbolic merge^-1 >actual && |
| 167 | test_cmp expect actual |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'rev-parse merge^-0 (invalid parent)' ' |
| 171 | test_must_fail git rev-parse merge^-0 |
| 172 | ' |
| 173 | |
| 174 | test_expect_success 'rev-parse merge^-3 (invalid parent)' ' |
| 175 | test_must_fail git rev-parse merge^-3 |
| 176 | ' |
| 177 | |
| 178 | test_expect_success 'rev-parse merge^-^ (garbage after ^-)' ' |
| 179 | test_must_fail git rev-parse merge^-^ |
| 180 | ' |
| 181 | |
| 182 | test_expect_success 'rev-parse merge^-1x (garbage after ^-1)' ' |
| 183 | test_must_fail git rev-parse merge^-1x |
| 184 | ' |
| 185 | |
| 186 | # All rev^- rev-list tests (should be mostly the same as rev-parse; the reason |
| 187 | # for the duplication is that rev-parse and rev-list use different parsers). |
| 188 | |
| 189 | test_expect_success 'rev-list merge^- = merge^..merge' ' |
| 190 | git rev-list merge^..merge >expect && |
| 191 | git rev-list merge^- >actual && |
| 192 | test_cmp expect actual |
| 193 | ' |
| 194 | |
| 195 | test_expect_success 'rev-list merge^-1 = merge^1..merge' ' |
| 196 | git rev-list merge^1..merge >expect && |
| 197 | git rev-list merge^-1 >actual && |
| 198 | test_cmp expect actual |
| 199 | ' |
| 200 | |
| 201 | test_expect_success 'rev-list merge^-2 = merge^2..merge' ' |
| 202 | git rev-list merge^2..merge >expect && |
| 203 | git rev-list merge^-2 >actual && |
| 204 | test_cmp expect actual |
| 205 | ' |
| 206 | |
| 207 | test_expect_success 'rev-list merge^-0 (invalid parent)' ' |
| 208 | test_must_fail git rev-list merge^-0 |
| 209 | ' |
| 210 | |
| 211 | test_expect_success 'rev-list merge^-3 (invalid parent)' ' |
| 212 | test_must_fail git rev-list merge^-3 |
| 213 | ' |
| 214 | |
| 215 | test_expect_success 'rev-list merge^-^ (garbage after ^-)' ' |
| 216 | test_must_fail git rev-list merge^-^ |
| 217 | ' |
| 218 | |
| 219 | test_expect_success 'rev-list merge^-1x (garbage after ^-1)' ' |
| 220 | test_must_fail git rev-list merge^-1x |
| 221 | ' |
| 222 | |
| 223 | test_expect_success 'rev-parse $garbage^@ does not segfault' ' |
| 224 | test_must_fail git rev-parse $EMPTY_TREE^@ |
| 225 | ' |
| 226 | |
| 227 | test_expect_success 'rev-parse $garbage...$garbage does not segfault' ' |
| 228 | test_must_fail git rev-parse $EMPTY_TREE...$EMPTY_BLOB |
| 229 | ' |
| 230 | |
| 231 | test_done |