| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='detect unwritable repository and fail correctly' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success setup ' |
| 8 | |
| 9 | >file && |
| 10 | git add file && |
| 11 | test_tick && |
| 12 | git commit -m initial && |
| 13 | echo >file && |
| 14 | git add file |
| 15 | |
| 16 | ' |
| 17 | |
| 18 | test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' ' |
| 19 | test_when_finished "chmod 775 .git/objects .git/objects/??" && |
| 20 | chmod a-w .git/objects .git/objects/?? && |
| 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 |
| 31 | ' |
| 32 | |
| 33 | test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' ' |
| 34 | test_when_finished "chmod 775 .git/objects .git/objects/??" && |
| 35 | chmod a-w .git/objects .git/objects/?? && |
| 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_success 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 |
| 46 | ' |
| 47 | |
| 48 | test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' ' |
| 49 | test_when_finished "chmod 775 .git/objects .git/objects/??" && |
| 50 | echo 6O >file && |
| 51 | chmod a-w .git/objects .git/objects/?? && |
| 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 |
| 63 | ' |
| 64 | |
| 65 | test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' ' |
| 66 | test_when_finished "chmod 775 .git/objects .git/objects/??" && |
| 67 | echo b >file && |
| 68 | chmod a-w .git/objects .git/objects/?? && |
| 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 |
| 81 | ' |
| 82 | |
| 83 | test_done |