| 1 | git_show_ref_exists=${git_show_ref_exists:-git show-ref --exists} |
| 2 | |
| 3 | test_expect_success setup ' |
| 4 | test_commit --annotate A && |
| 5 | git checkout -b side && |
| 6 | test_commit --annotate B && |
| 7 | git checkout main && |
| 8 | test_commit C && |
| 9 | git branch B A^0 |
| 10 | ' |
| 11 | |
| 12 | test_expect_success '--exists with existing reference' ' |
| 13 | ${git_show_ref_exists} refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 14 | ' |
| 15 | |
| 16 | test_expect_success '--exists with missing reference' ' |
| 17 | test_expect_code 2 ${git_show_ref_exists} refs/heads/does-not-exist |
| 18 | ' |
| 19 | |
| 20 | test_expect_success '--exists does not use DWIM' ' |
| 21 | test_expect_code 2 ${git_show_ref_exists} $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err && |
| 22 | test_grep "reference does not exist" err |
| 23 | ' |
| 24 | |
| 25 | test_expect_success '--exists with HEAD' ' |
| 26 | ${git_show_ref_exists} HEAD |
| 27 | ' |
| 28 | |
| 29 | test_expect_success '--exists with bad reference name' ' |
| 30 | test_when_finished "git update-ref -d refs/heads/bad...name" && |
| 31 | new_oid=$(git rev-parse HEAD) && |
| 32 | test-tool ref-store main update-ref msg refs/heads/bad...name $new_oid $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && |
| 33 | ${git_show_ref_exists} refs/heads/bad...name |
| 34 | ' |
| 35 | |
| 36 | test_expect_success '--exists with arbitrary symref' ' |
| 37 | test_when_finished "git symbolic-ref -d refs/symref" && |
| 38 | git symbolic-ref refs/symref refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME && |
| 39 | ${git_show_ref_exists} refs/symref |
| 40 | ' |
| 41 | |
| 42 | test_expect_success '--exists with dangling symref' ' |
| 43 | test_when_finished "git symbolic-ref -d refs/heads/dangling" && |
| 44 | git symbolic-ref refs/heads/dangling refs/heads/does-not-exist && |
| 45 | ${git_show_ref_exists} refs/heads/dangling |
| 46 | ' |
| 47 | |
| 48 | test_expect_success '--exists with nonexistent object ID' ' |
| 49 | test-tool ref-store main update-ref msg refs/heads/missing-oid $(test_oid 001) $ZERO_OID REF_SKIP_OID_VERIFICATION && |
| 50 | ${git_show_ref_exists} refs/heads/missing-oid |
| 51 | ' |
| 52 | |
| 53 | test_expect_success '--exists with non-commit object' ' |
| 54 | tree_oid=$(git rev-parse HEAD^{tree}) && |
| 55 | test-tool ref-store main update-ref msg refs/heads/tree ${tree_oid} $ZERO_OID REF_SKIP_OID_VERIFICATION && |
| 56 | ${git_show_ref_exists} refs/heads/tree |
| 57 | ' |
| 58 | |
| 59 | test_expect_success '--exists with directory fails with generic error' ' |
| 60 | cat >expect <<-EOF && |
| 61 | error: reference does not exist |
| 62 | EOF |
| 63 | test_expect_code 2 ${git_show_ref_exists} refs/heads 2>err && |
| 64 | test_cmp expect err |
| 65 | ' |
| 66 | |
| 67 | test_expect_success '--exists with non-existent special ref' ' |
| 68 | test_expect_code 2 ${git_show_ref_exists} FETCH_HEAD |
| 69 | ' |
| 70 | |
| 71 | test_expect_success '--exists with existing special ref' ' |
| 72 | test_when_finished "rm .git/FETCH_HEAD" && |
| 73 | git rev-parse HEAD >.git/FETCH_HEAD && |
| 74 | ${git_show_ref_exists} FETCH_HEAD |
| 75 | ' |
| 76 | |
| 77 | test_done |