git/t/t0004-unwritable.sh
Ævar Arnfjörð Bjarmason c91cfd1916 tests: A SANITY test prereq for testing if we're root
Some tests depend on not being able to write to files after chmod
-w. This doesn't work when running the tests as root.

Change test-lib.sh to test if this works, and if so it sets a new
SANITY test prerequisite. The tests that use this previously failed
when run under root.

There was already a test for this in t3600-rm.sh, added by Junio C
Hamano in 2283645 in 2006. That check now uses the new SANITY
prerequisite.

Some of this was resurrected from the "Tests in Cygwin" thread in May
2009:

    http://thread.gmane.org/gmane.comp.version-control.git/116729/focus=118385

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-18 12:42:04 -07:00

69 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
test_description='detect unwritable repository and fail correctly'
. ./test-lib.sh
test_expect_success setup '
>file &&
git add file &&
test_tick &&
git commit -m initial &&
echo >file &&
git add file
'
test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' '
(
chmod a-w .git/objects .git/objects/?? &&
test_must_fail git write-tree
)
status=$?
chmod 775 .git/objects .git/objects/??
(exit $status)
'
test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' '
(
chmod a-w .git/objects .git/objects/?? &&
test_must_fail git commit -m second
)
status=$?
chmod 775 .git/objects .git/objects/??
(exit $status)
'
test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' '
(
echo 6O >file &&
chmod a-w .git/objects .git/objects/?? &&
test_must_fail git update-index file
)
status=$?
chmod 775 .git/objects .git/objects/??
(exit $status)
'
test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '
(
echo b >file &&
chmod a-w .git/objects .git/objects/?? &&
test_must_fail git add file
)
status=$?
chmod 775 .git/objects .git/objects/??
(exit $status)
'
test_done