]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t1401-symbolic-ref: avoid direct filesystem access
authorHan-Wen Nienhuys <hanwen@google.com>
Mon, 31 May 2021 16:56:21 +0000 (16:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Jun 2021 01:01:54 +0000 (10:01 +0900)
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>
t/t1401-symbolic-ref.sh

index 7a9629fb9f0ecdac070ed07fd04ff4792dba1f5d..132a1b885acbce46cb9f8a1b52fc2833fc8a7990 100755 (executable)
@@ -17,14 +17,9 @@ test_expect_success 'setup' '
        "$TAR" cf .git.tar .git/
 '
 
-test_expect_success 'symbolic-ref writes HEAD' '
-       git symbolic-ref HEAD refs/heads/foo &&
-       echo ref: refs/heads/foo >expect &&
-       test_cmp expect .git/HEAD
-'
-
-test_expect_success 'symbolic-ref reads HEAD' '
-       echo refs/heads/foo >expect &&
+test_expect_success 'symbolic-ref read/write roundtrip' '
+       git symbolic-ref HEAD refs/heads/read-write-roundtrip &&
+       echo refs/heads/read-write-roundtrip >expect &&
        git symbolic-ref HEAD >actual &&
        test_cmp expect actual
 '
@@ -32,12 +27,13 @@ test_expect_success 'symbolic-ref reads HEAD' '
 test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
        test_must_fail git symbolic-ref HEAD foo
 '
+
 reset_to_sane
 
 test_expect_success 'symbolic-ref refuses bare sha1' '
-       echo content >file && git add file && git commit -m one &&
        test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
 '
+
 reset_to_sane
 
 test_expect_success 'HEAD cannot be removed' '
@@ -49,16 +45,16 @@ reset_to_sane
 test_expect_success 'symbolic-ref can be deleted' '
        git symbolic-ref NOTHEAD refs/heads/foo &&
        git symbolic-ref -d NOTHEAD &&
-       test_path_is_file .git/refs/heads/foo &&
-       test_path_is_missing .git/NOTHEAD
+       git rev-parse refs/heads/foo &&
+       test_must_fail git symbolic-ref NOTHEAD
 '
 reset_to_sane
 
 test_expect_success 'symbolic-ref can delete dangling symref' '
        git symbolic-ref NOTHEAD refs/heads/missing &&
        git symbolic-ref -d NOTHEAD &&
-       test_path_is_missing .git/refs/heads/missing &&
-       test_path_is_missing .git/NOTHEAD
+       test_must_fail git rev-parse refs/heads/missing &&
+       test_must_fail git symbolic-ref NOTHEAD
 '
 reset_to_sane