Git fork

t1403: split 'show-ref --exists' tests into a separate file

The test file for git-show-ref(1), `t1403-show-ref.sh`, contains a group
of tests for the '--exists' flag. To improve organization and to prepare
for refactoring these tests to be shareable, move the '--exists' tests
and their corresponding setup logic into a self-contained test suite,
`t1422-show-ref-exists.sh`.

This is a pure code-movement refactoring with no change in test coverage
or behavior.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Meet Soni and committed by
Junio C Hamano
0749b93a 0f0a8a11

+85 -66
+2 -1
t/meson.build
··· 205 205 't1419-exclude-refs.sh', 206 206 't1420-lost-found.sh', 207 207 't1421-reflog-write.sh', 208 + 't1422-show-ref-exists.sh', 208 209 't1430-bad-ref-name.sh', 209 210 't1450-fsck.sh', 210 211 't1451-fsck-buffer.sh', ··· 1216 1217 timeout: 0, 1217 1218 ) 1218 1219 endforeach 1219 - endif 1220 + endif
-65
t/t1403-show-ref.sh
··· 228 228 grep "cannot be used together" err 229 229 ' 230 230 231 - test_expect_success '--exists with existing reference' ' 232 - git show-ref --exists refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 233 - ' 234 - 235 - test_expect_success '--exists with missing reference' ' 236 - test_expect_code 2 git show-ref --exists refs/heads/does-not-exist 237 - ' 238 - 239 - test_expect_success '--exists does not use DWIM' ' 240 - test_expect_code 2 git show-ref --exists $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err && 241 - grep "reference does not exist" err 242 - ' 243 - 244 - test_expect_success '--exists with HEAD' ' 245 - git show-ref --exists HEAD 246 - ' 247 - 248 - test_expect_success '--exists with bad reference name' ' 249 - test_when_finished "git update-ref -d refs/heads/bad...name" && 250 - new_oid=$(git rev-parse HEAD) && 251 - test-tool ref-store main update-ref msg refs/heads/bad...name $new_oid $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && 252 - git show-ref --exists refs/heads/bad...name 253 - ' 254 - 255 - test_expect_success '--exists with arbitrary symref' ' 256 - test_when_finished "git symbolic-ref -d refs/symref" && 257 - git symbolic-ref refs/symref refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME && 258 - git show-ref --exists refs/symref 259 - ' 260 - 261 - test_expect_success '--exists with dangling symref' ' 262 - test_when_finished "git symbolic-ref -d refs/heads/dangling" && 263 - git symbolic-ref refs/heads/dangling refs/heads/does-not-exist && 264 - git show-ref --exists refs/heads/dangling 265 - ' 266 - 267 - test_expect_success '--exists with nonexistent object ID' ' 268 - test-tool ref-store main update-ref msg refs/heads/missing-oid $(test_oid 001) $ZERO_OID REF_SKIP_OID_VERIFICATION && 269 - git show-ref --exists refs/heads/missing-oid 270 - ' 271 - 272 - test_expect_success '--exists with non-commit object' ' 273 - tree_oid=$(git rev-parse HEAD^{tree}) && 274 - test-tool ref-store main update-ref msg refs/heads/tree ${tree_oid} $ZERO_OID REF_SKIP_OID_VERIFICATION && 275 - git show-ref --exists refs/heads/tree 276 - ' 277 - 278 - test_expect_success '--exists with directory fails with generic error' ' 279 - cat >expect <<-EOF && 280 - error: reference does not exist 281 - EOF 282 - test_expect_code 2 git show-ref --exists refs/heads 2>err && 283 - test_cmp expect err 284 - ' 285 - 286 - test_expect_success '--exists with non-existent special ref' ' 287 - test_expect_code 2 git show-ref --exists FETCH_HEAD 288 - ' 289 - 290 - test_expect_success '--exists with existing special ref' ' 291 - test_when_finished "rm .git/FETCH_HEAD" && 292 - git rev-parse HEAD >.git/FETCH_HEAD && 293 - git show-ref --exists FETCH_HEAD 294 - ' 295 - 296 231 test_done
+83
t/t1422-show-ref-exists.sh
··· 1 + #!/bin/sh 2 + 3 + test_description='show-ref --exists' 4 + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5 + export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 + 7 + . ./test-lib.sh 8 + 9 + test_expect_success setup ' 10 + test_commit --annotate A && 11 + git checkout -b side && 12 + test_commit --annotate B && 13 + git checkout main && 14 + test_commit C && 15 + git branch B A^0 16 + ' 17 + 18 + test_expect_success '--exists with existing reference' ' 19 + git show-ref --exists refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 20 + ' 21 + 22 + test_expect_success '--exists with missing reference' ' 23 + test_expect_code 2 git show-ref --exists refs/heads/does-not-exist 24 + ' 25 + 26 + test_expect_success '--exists does not use DWIM' ' 27 + test_expect_code 2 git show-ref --exists $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err && 28 + grep "reference does not exist" err 29 + ' 30 + 31 + test_expect_success '--exists with HEAD' ' 32 + git show-ref --exists HEAD 33 + ' 34 + 35 + test_expect_success '--exists with bad reference name' ' 36 + test_when_finished "git update-ref -d refs/heads/bad...name" && 37 + new_oid=$(git rev-parse HEAD) && 38 + test-tool ref-store main update-ref msg refs/heads/bad...name $new_oid $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && 39 + git show-ref --exists refs/heads/bad...name 40 + ' 41 + 42 + test_expect_success '--exists with arbitrary symref' ' 43 + test_when_finished "git symbolic-ref -d refs/symref" && 44 + git symbolic-ref refs/symref refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME && 45 + git show-ref --exists refs/symref 46 + ' 47 + 48 + test_expect_success '--exists with dangling symref' ' 49 + test_when_finished "git symbolic-ref -d refs/heads/dangling" && 50 + git symbolic-ref refs/heads/dangling refs/heads/does-not-exist && 51 + git show-ref --exists refs/heads/dangling 52 + ' 53 + 54 + test_expect_success '--exists with nonexistent object ID' ' 55 + test-tool ref-store main update-ref msg refs/heads/missing-oid $(test_oid 001) $ZERO_OID REF_SKIP_OID_VERIFICATION && 56 + git show-ref --exists refs/heads/missing-oid 57 + ' 58 + 59 + test_expect_success '--exists with non-commit object' ' 60 + tree_oid=$(git rev-parse HEAD^{tree}) && 61 + test-tool ref-store main update-ref msg refs/heads/tree ${tree_oid} $ZERO_OID REF_SKIP_OID_VERIFICATION && 62 + git show-ref --exists refs/heads/tree 63 + ' 64 + 65 + test_expect_success '--exists with directory fails with generic error' ' 66 + cat >expect <<-EOF && 67 + error: reference does not exist 68 + EOF 69 + test_expect_code 2 git show-ref --exists refs/heads 2>err && 70 + test_cmp expect err 71 + ' 72 + 73 + test_expect_success '--exists with non-existent special ref' ' 74 + test_expect_code 2 git show-ref --exists FETCH_HEAD 75 + ' 76 + 77 + test_expect_success '--exists with existing special ref' ' 78 + test_when_finished "rm .git/FETCH_HEAD" && 79 + git rev-parse HEAD >.git/FETCH_HEAD && 80 + git show-ref --exists FETCH_HEAD 81 + ' 82 + 83 + test_done