Skip to content

Commit 0749b93

Browse files
inosmeetgitster
authored andcommitted
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 <[email protected]> Mentored-by: shejialuo <[email protected]> Signed-off-by: Meet Soni <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f0a8a1 commit 0749b93

File tree

3 files changed

+85
-66
lines changed

3 files changed

+85
-66
lines changed

t/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ integration_tests = [
205205
't1419-exclude-refs.sh',
206206
't1420-lost-found.sh',
207207
't1421-reflog-write.sh',
208+
't1422-show-ref-exists.sh',
208209
't1430-bad-ref-name.sh',
209210
't1450-fsck.sh',
210211
't1451-fsck-buffer.sh',
@@ -1216,4 +1217,4 @@ if perl.found() and time.found()
12161217
timeout: 0,
12171218
)
12181219
endforeach
1219-
endif
1220+
endif

t/t1403-show-ref.sh

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -228,69 +228,4 @@ test_expect_success 'show-ref sub-modes are mutually exclusive' '
228228
grep "cannot be used together" err
229229
'
230230

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-
296231
test_done

t/t1422-show-ref-exists.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

0 commit comments

Comments
 (0)