t1401-symbolic-ref: avoid direct filesystem access

Use symbolic-ref and rev-parse to inspect refs. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Reviewed-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Han-Wen Nienhuys committed May 31, 2021 at 16:56 UTC b1259ecff9a51de22ac8a70fc26c20dde8a18f80
1 file changed +9 -13
t/t1401-symbolic-ref.sh
+9 -13
@@ -17,14 +17,9 @@ test_expect_success 'setup' '
17 "$TAR" cf .git.tar .git/
18 '
19
20 -test_expect_success 'symbolic-ref writes HEAD' '
21 - git symbolic-ref HEAD refs/heads/foo &&
22 - echo ref: refs/heads/foo >expect &&
23 - test_cmp expect .git/HEAD
24 -'
25 -
26 -test_expect_success 'symbolic-ref reads HEAD' '
27 - echo refs/heads/foo >expect &&
20 +test_expect_success 'symbolic-ref read/write roundtrip' '
21 + git symbolic-ref HEAD refs/heads/read-write-roundtrip &&
22 + echo refs/heads/read-write-roundtrip >expect &&
23 git symbolic-ref HEAD >actual &&
24 test_cmp expect actual
25 '
@@ -32,12 +27,13 @@ test_expect_success 'symbolic-ref reads HEAD' '
27 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
28 test_must_fail git symbolic-ref HEAD foo
29 '
30 +
31 reset_to_sane
32
33 test_expect_success 'symbolic-ref refuses bare sha1' '
38 - echo content >file && git add file && git commit -m one &&
34 test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
35 '
36 +
37 reset_to_sane
38
39 test_expect_success 'HEAD cannot be removed' '
@@ -49,16 +45,16 @@ reset_to_sane
45 test_expect_success 'symbolic-ref can be deleted' '
46 git symbolic-ref NOTHEAD refs/heads/foo &&
47 git symbolic-ref -d NOTHEAD &&
52 - test_path_is_file .git/refs/heads/foo &&
53 - test_path_is_missing .git/NOTHEAD
48 + git rev-parse refs/heads/foo &&
49 + test_must_fail git symbolic-ref NOTHEAD
50 '
51 reset_to_sane
52
53 test_expect_success 'symbolic-ref can delete dangling symref' '
54 git symbolic-ref NOTHEAD refs/heads/missing &&
55 git symbolic-ref -d NOTHEAD &&
60 - test_path_is_missing .git/refs/heads/missing &&
61 - test_path_is_missing .git/NOTHEAD
56 + test_must_fail git rev-parse refs/heads/missing &&
57 + test_must_fail git symbolic-ref NOTHEAD
58 '
59 reset_to_sane
60