test-lib: Introduce test_chmod and use it instead of update-index --chmod

This function replaces sequences of 'chmod +x' and 'git update-index
--chmod=+x' in the test suite, whose purpose is to help filesystems
that need core.filemode=false. Two places where only 'chmod +x' was used
we also use this new function.

The function calls 'git update-index --chmod' without checking
core.filemode (unlike some of the call sites did). We do this because the
call sites *expect* that the executable bit ends up in the index (ie. it
is not the purpose of the call sites to *test* whether git treats
'chmod +x' and 'update-index --chmod=+x' correctly). Therefore, on
filesystems with core.filemode=true the 'git update-index --chmod' is a
no-op.

The function uses --add with update-index to help one call site in
t6031-merge-recursive. It makes no difference for the other callers.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
This commit is contained in:
Johannes Sixt 2009-02-28 21:12:57 +01:00
parent 8586f98bd2
commit 1f553918a8
7 changed files with 24 additions and 43 deletions

View file

@ -70,9 +70,7 @@ test_expect_success setup '
E=`git rev-parse --verify HEAD:A/B/E` &&
check_fsck &&
chmod +x C &&
( test "`git config --bool core.filemode`" != false ||
echo executable >>C ) &&
test_chmod +x C &&
git add C &&
test_tick && git commit -m dragon &&
L=`git rev-parse --verify HEAD` &&

View file

@ -83,9 +83,9 @@ test_expect_success 'rebase a single mode change' '
git checkout -b modechange HEAD^ &&
echo 1 > X &&
git add X &&
chmod a+x A &&
test_chmod +x A &&
test_tick &&
git commit -m modechange A X &&
git commit -m modechange &&
GIT_TRACE=1 git rebase master
'

View file

@ -15,21 +15,10 @@ test_expect_success \
tree=`git write-tree` &&
echo $tree'
if [ "$(git config --get core.filemode)" = false ]
then
say 'filemode disabled on the filesystem, using update-index --chmod=+x'
test_expect_success \
'git update-index --chmod=+x' \
'git update-index rezrov &&
git update-index --chmod=+x rezrov &&
git diff-index $tree >current'
else
test_expect_success \
'chmod' \
'chmod +x rezrov &&
git update-index rezrov &&
git diff-index $tree >current'
fi
test_expect_success \
'chmod' \
'test_chmod +x rezrov &&
git diff-index $tree >current'
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"

View file

@ -16,9 +16,7 @@ test_expect_success setup '
git checkout -b side &&
for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
chmod +x elif &&
git update-index file elif &&
git update-index --chmod=+x elif &&
test_chmod +x elif &&
git commit -m "Side changes #1" &&
for i in D E F; do echo "$i"; done >>file &&

View file

@ -3,9 +3,6 @@
test_description='merge-recursive: handle file mode'
. ./test-lib.sh
# Note that we follow "chmod +x F" with "update-index --chmod=+x F" to
# help filesystems that do not have the executable bit.
test_expect_success 'mode change in one branch: keep changed version' '
: >file1 &&
git add file1 &&
@ -15,8 +12,7 @@ test_expect_success 'mode change in one branch: keep changed version' '
git add dummy &&
git commit -m a &&
git checkout -b b1 master &&
chmod +x file1 &&
git update-index --chmod=+x file1 &&
test_chmod +x file1 &&
git commit -m b1 &&
git checkout a1 &&
git merge-recursive master -- a1 b1 &&
@ -28,8 +24,7 @@ test_expect_success 'mode change in both branches: expect conflict' '
git checkout -b a2 master &&
: >file2 &&
H=$(git hash-object file2) &&
chmod +x file2 &&
git update-index --add --chmod=+x file2 &&
test_chmod +x file2 &&
git commit -m a2 &&
git checkout -b b2 master &&
: >file2 &&

View file

@ -63,14 +63,6 @@ gitweb_run () {
# gitweb.log is left for debugging
}
safe_chmod () {
chmod "$1" "$2" &&
if [ "$(git config --get core.filemode)" = false ]
then
git update-index --chmod="$1" "$2"
fi
}
. ./test-lib.sh
perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
@ -242,7 +234,7 @@ test_debug 'cat gitweb.log'
test_expect_success \
'commitdiff(0): mode change' \
'safe_chmod +x new_file &&
'test_chmod +x new_file &&
git commit -a -m "Mode changed." &&
gitweb_run "p=.git;a=commitdiff"'
test_debug 'cat gitweb.log'
@ -281,7 +273,7 @@ test_debug 'cat gitweb.log'
test_expect_success \
'commitdiff(0): mode change and modified' \
'echo "New line" >> file2 &&
safe_chmod +x file2 &&
test_chmod +x file2 &&
git commit -a -m "Mode change and modification." &&
gitweb_run "p=.git;a=commitdiff"'
test_debug 'cat gitweb.log'
@ -308,7 +300,7 @@ test_expect_success \
'commitdiff(0): renamed, mode change and modified' \
'git mv file3 file2 &&
echo "Propter nomen suum." >> file2 &&
safe_chmod +x file2 &&
test_chmod +x file2 &&
git commit -a -m "File rename, mode change and modification." &&
gitweb_run "p=.git;a=commitdiff"'
test_debug 'cat gitweb.log'
@ -425,10 +417,10 @@ test_expect_success \
git add 03-new &&
git mv 04-rename-from 04-rename-to &&
echo "Changed" >> 04-rename-to &&
safe_chmod +x 05-mode-change &&
test_chmod +x 05-mode-change &&
rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
echo "Changed and have mode changed" > 07-change-mode-change &&
safe_chmod +x 07-change-mode-change &&
test_chmod +x 07-change-mode-change &&
git commit -a -m "Large commit" &&
git checkout master'

View file

@ -238,6 +238,15 @@ test_merge () {
git tag "$1"
}
# This function helps systems where core.filemode=false is set.
# Use it instead of plain 'chmod +x' to set or unset the executable bit
# of a file in the working directory and add it to the index.
test_chmod () {
chmod "$@" &&
git update-index --add "--chmod=$@"
}
# You are not expected to call test_ok_ and test_failure_ directly, use
# the text_expect_* functions instead.