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
9
+. "$TEST_DIRECTORY"/show-ref-exists-tests.sh