Skip to content

Commit 329636b

Browse files
committed
t0004: fix timing bug
The test created an initial commit, made .git/objects unwritable and then exercised various codepaths to create loose commit, tree and blob objects to make sure the commands notice failures from these attempts. However, the initial commit was not preceded with test_tick, which made its object name depend on the timestamp. The names of all the later tree and blob objects the test tried to create were static. If the initial commit's object name happened to begin with the same two hexdigits as the tree or blob objects the test later attempted to create, the fan-out directory in which these tree or blob would be created is already created when the initial commit was made, and the object creation succeeds, and commands being tested should not notice any failure --- in short, the test was bogus. This makes the fan-out directories also unwritable, and adds test_tick before the commit object creation to make the test repeatable. The contents of the file to create a blob from "a" to "60" is to force the name of the blob object to begin with "1b", which shares the fan-out directory with the initial commit that is created with the test. This was useful when diagnosing the breakage of this test. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b495818 commit 329636b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

t/t0004-unwritable.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_expect_success setup '
88
99
>file &&
1010
git add file &&
11+
test_tick &&
1112
git commit -m initial &&
1213
echo >file &&
1314
git add file
@@ -17,36 +18,36 @@ test_expect_success setup '
1718
test_expect_success 'write-tree should notice unwritable repository' '
1819
1920
(
20-
chmod a-w .git/objects
21+
chmod a-w .git/objects .git/objects/?? &&
2122
test_must_fail git write-tree
2223
)
2324
status=$?
24-
chmod 775 .git/objects
25+
chmod 775 .git/objects .git/objects/??
2526
(exit $status)
2627
2728
'
2829

2930
test_expect_success 'commit should notice unwritable repository' '
3031
3132
(
32-
chmod a-w .git/objects
33+
chmod a-w .git/objects .git/objects/?? &&
3334
test_must_fail git commit -m second
3435
)
3536
status=$?
36-
chmod 775 .git/objects
37+
chmod 775 .git/objects .git/objects/??
3738
(exit $status)
3839
3940
'
4041

4142
test_expect_success 'update-index should notice unwritable repository' '
4243
4344
(
44-
echo a >file &&
45-
chmod a-w .git/objects
45+
echo 6O >file &&
46+
chmod a-w .git/objects .git/objects/?? &&
4647
test_must_fail git update-index file
4748
)
4849
status=$?
49-
chmod 775 .git/objects
50+
chmod 775 .git/objects .git/objects/??
5051
(exit $status)
5152
5253
'
@@ -55,11 +56,11 @@ test_expect_success 'add should notice unwritable repository' '
5556
5657
(
5758
echo b >file &&
58-
chmod a-w .git/objects
59+
chmod a-w .git/objects .git/objects/?? &&
5960
test_must_fail git add file
6061
)
6162
status=$?
62-
chmod 775 .git/objects
63+
chmod 775 .git/objects .git/objects/??
6364
(exit $status)
6465
6566
'

0 commit comments

Comments
 (0)