Skip to content

Commit 119b26d

Browse files
avargitster
authored andcommitted
unwritable tests: assert exact error output
In preparation for fixing a regression where we started emitting some of these error messages twice, let's assert what the output from "git commit" and friends is now in the case of permission errors. As noted in [1] using test_expect_failure to mark up a TODO test has some unexpected edge cases, e.g. we don't want to break --run=3 by skipping the "test_lazy_prereq" here. This pattern allows us to test just the test_cmp (and the "cat", which shouldn't fail) with the added "test_expect_failure", we'll flip that to a "test_expect_success" in the next commit. 1. https://lore.kernel.org/git/[email protected]/T/#u Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit 119b26d

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

t/t0004-unwritable.sh

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,66 @@ test_expect_success setup '
1818
test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' '
1919
test_when_finished "chmod 775 .git/objects .git/objects/??" &&
2020
chmod a-w .git/objects .git/objects/?? &&
21-
test_must_fail git write-tree
21+
test_must_fail git write-tree 2>out.write-tree
22+
'
23+
24+
test_lazy_prereq WRITE_TREE_OUT 'test -e "$TRASH_DIRECTORY"/out.write-tree'
25+
test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository' '
26+
cat >expect <<-\EOF &&
27+
error: insufficient permission for adding an object to repository database .git/objects
28+
fatal: git-write-tree: error building trees
29+
EOF
30+
test_cmp expect out.write-tree
2231
'
2332

2433
test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
2534
test_when_finished "chmod 775 .git/objects .git/objects/??" &&
2635
chmod a-w .git/objects .git/objects/?? &&
27-
test_must_fail git commit -m second
36+
test_must_fail git commit -m second 2>out.commit
37+
'
38+
39+
test_lazy_prereq COMMIT_OUT 'test -e "$TRASH_DIRECTORY"/out.commit'
40+
test_expect_failure COMMIT_OUT 'commit output on unwritable repository' '
41+
cat >expect <<-\EOF &&
42+
error: insufficient permission for adding an object to repository database .git/objects
43+
error: Error building trees
44+
EOF
45+
test_cmp expect out.commit
2846
'
2947

3048
test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' '
3149
test_when_finished "chmod 775 .git/objects .git/objects/??" &&
3250
echo 6O >file &&
3351
chmod a-w .git/objects .git/objects/?? &&
34-
test_must_fail git update-index file
52+
test_must_fail git update-index file 2>out.update-index
53+
'
54+
55+
test_lazy_prereq UPDATE_INDEX_OUT 'test -e "$TRASH_DIRECTORY"/out.update-index'
56+
test_expect_success UPDATE_INDEX_OUT 'update-index output on unwritable repository' '
57+
cat >expect <<-\EOF &&
58+
error: insufficient permission for adding an object to repository database .git/objects
59+
error: file: failed to insert into database
60+
fatal: Unable to process path file
61+
EOF
62+
test_cmp expect out.update-index
3563
'
3664

3765
test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
3866
test_when_finished "chmod 775 .git/objects .git/objects/??" &&
3967
echo b >file &&
4068
chmod a-w .git/objects .git/objects/?? &&
41-
test_must_fail git add file
69+
test_must_fail git add file 2>out.add
70+
'
71+
72+
test_lazy_prereq ADD_OUT 'test -e "$TRASH_DIRECTORY"/out.add'
73+
test_expect_success ADD_OUT 'add output on unwritable repository' '
74+
cat >expect <<-\EOF &&
75+
error: insufficient permission for adding an object to repository database .git/objects
76+
error: file: failed to insert into database
77+
error: unable to index file '\''file'\''
78+
fatal: updating files failed
79+
EOF
80+
test_cmp expect out.add
4281
'
4382

4483
test_done

0 commit comments

Comments
 (0)