Skip to content

Commit 0377142

Browse files
committed
tests: clean after SANITY tests
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 <[email protected]>
1 parent fc54c1a commit 0377142

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

t/t0001-init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ test_expect_success 'init notices EEXIST (2)' '
287287
'
288288

289289
test_expect_success POSIXPERM,SANITY 'init notices EPERM' '
290+
test_when_finished "chmod +w newdir" &&
290291
rm -fr newdir &&
291292
mkdir newdir &&
292293
chmod -w newdir &&

t/t0070-fundamental.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ test_expect_success 'mktemp to nonexistent directory prints filename' '
1919

2020
test_expect_success POSIXPERM,SANITY 'mktemp to unwritable directory prints filename' '
2121
mkdir cannotwrite &&
22-
chmod -w cannotwrite &&
2322
test_when_finished "chmod +w cannotwrite" &&
23+
chmod -w cannotwrite &&
2424
test_must_fail test-mktemp cannotwrite/testXXXXXX 2>err &&
2525
grep "cannotwrite/test" err
2626
'

t/t1004-read-tree-m-u-wf.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ test_expect_success 'funny symlink in work tree' '
179179

180180
test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
181181
182+
test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
183+
182184
rm -fr a b &&
183185
git reset --hard &&
184186
@@ -188,10 +190,6 @@ test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
188190
189191
'
190192

191-
# clean-up from the above test
192-
chmod a+w a 2>/dev/null
193-
rm -fr a b
194-
195193
test_expect_success 'D/F setup' '
196194
197195
git reset --hard &&

t/t5537-fetch-shallow.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ EOF
175175

176176
test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
177177
cp -R .git read-only.git &&
178-
find read-only.git -print | xargs chmod -w &&
179178
test_when_finished "find read-only.git -type d -print | xargs chmod +w" &&
179+
find read-only.git -print | xargs chmod -w &&
180180
git clone --no-local --depth=2 read-only.git from-read-only &&
181181
git --git-dir=from-read-only/.git log --format=%s >actual &&
182182
cat >expect <<EOF &&

t/t7508-status.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ EOF
10991099
'
11001100

11011101
test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
1102+
test_when_finished "chmod 775 .git" &&
11021103
(
11031104
chmod a-w .git &&
11041105
# make dir1/tracked stat-dirty
@@ -1108,9 +1109,6 @@ test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository'
11081109
# make sure "status" succeeded without writing index out
11091110
git diff-files | grep dir1/tracked
11101111
)
1111-
status=$?
1112-
chmod 775 .git
1113-
(exit $status)
11141112
'
11151113

11161114
(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm

0 commit comments

Comments
 (0)