]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tests: clean after SANITY tests
authorJunio C Hamano <gitster@pobox.com>
Fri, 15 Jun 2018 18:13:39 +0000 (11:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Jun 2018 18:20:08 +0000 (11:20 -0700)
Some of our tests try to make sure Git behaves sensibly in a
read-only directory, by dropping 'w' permission bit before doing a
test and then restoring it after it is done.  The latter is needed
for the test framework to clean after itself without leaving a
leftover directory that cannot be removed.

Ancient parts of tests however arrange the above with

chmod a-w . &&
... do the test ...
status=$?
chmod 775 .
(exit $status)

which obviously would not work if the test somehow dies before it
has the chance to do "chmod 775".  Rewrite them by following a more
robust pattern recently written tests use, which is

test_when_finished "chmod 775 ." &&
chmod a-w . &&
... do the test ...

Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0001-init.sh
t/t0070-fundamental.sh
t/t1004-read-tree-m-u-wf.sh
t/t5537-fetch-shallow.sh
t/t7508-status.sh

index c413bff9cf1f3a79ef494b39844c42d3a8c877f1..4c865051e7dd3d27eee0e2666b4aaaaa46116d5c 100755 (executable)
@@ -287,6 +287,7 @@ test_expect_success 'init notices EEXIST (2)' '
 '
 
 test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
+       test_when_finished "chmod +w newdir" &&
        rm -fr newdir &&
        mkdir newdir &&
        chmod -w newdir &&
index 991ed2a48dbf15fb4cb794a587ad900071391e11..60e3de7b7b39a5ac7989062164fc8e33a0403b20 100755 (executable)
@@ -19,8 +19,8 @@ test_expect_success 'mktemp to nonexistent directory prints filename' '
 
 test_expect_success POSIXPERM,SANITY 'mktemp to unwritable directory prints filename' '
        mkdir cannotwrite &&
-       chmod -w cannotwrite &&
        test_when_finished "chmod +w cannotwrite" &&
+       chmod -w cannotwrite &&
        test_must_fail test-mktemp cannotwrite/testXXXXXX 2>err &&
        grep "cannotwrite/test" err
 '
index c7ce5d8bb588215d528fad5dfa6aa094d2a5d468..826cd32e231607e3cd46f9c0314908583c01a093 100755 (executable)
@@ -179,6 +179,8 @@ test_expect_success 'funny symlink in work tree' '
 
 test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
 
+       test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
+
        rm -fr a b &&
        git reset --hard &&
 
@@ -188,10 +190,6 @@ test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
 
 '
 
-# clean-up from the above test
-chmod a+w a 2>/dev/null
-rm -fr a b
-
 test_expect_success 'D/F setup' '
 
        git reset --hard &&
index df8d2f095a40f524b8318b98a7c4fb085d8010f4..943231af9638d14641811ea8196f8afdafdf6871 100755 (executable)
@@ -175,8 +175,8 @@ EOF
 
 test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
        cp -R .git read-only.git &&
-       find read-only.git -print | xargs chmod -w &&
        test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
+       find read-only.git -print | xargs chmod -w &&
        git clone --no-local --depth=2 read-only.git from-read-only &&
        git --git-dir=from-read-only/.git log --format=%s >actual &&
        cat >expect <<EOF &&
index 50052e28727dab74037a115003b6083256d7f344..10b084d89036987227803fbd9ad8a0482131ed13 100755 (executable)
@@ -1099,6 +1099,7 @@ EOF
 '
 
 test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
+       test_when_finished "chmod 775 .git" &&
        (
                chmod a-w .git &&
                # make dir1/tracked stat-dirty
@@ -1108,9 +1109,6 @@ test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository'
                # make sure "status" succeeded without writing index out
                git diff-files | grep dir1/tracked
        )
-       status=$?
-       chmod 775 .git
-       (exit $status)
 '
 
 (cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm