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:
@ -70,9 +70,7 @@ test_expect_success setup '
|
|||||||
E=`git rev-parse --verify HEAD:A/B/E` &&
|
E=`git rev-parse --verify HEAD:A/B/E` &&
|
||||||
check_fsck &&
|
check_fsck &&
|
||||||
|
|
||||||
chmod +x C &&
|
test_chmod +x C &&
|
||||||
( test "`git config --bool core.filemode`" != false ||
|
|
||||||
echo executable >>C ) &&
|
|
||||||
git add C &&
|
git add C &&
|
||||||
test_tick && git commit -m dragon &&
|
test_tick && git commit -m dragon &&
|
||||||
L=`git rev-parse --verify HEAD` &&
|
L=`git rev-parse --verify HEAD` &&
|
||||||
|
@ -83,9 +83,9 @@ test_expect_success 'rebase a single mode change' '
|
|||||||
git checkout -b modechange HEAD^ &&
|
git checkout -b modechange HEAD^ &&
|
||||||
echo 1 > X &&
|
echo 1 > X &&
|
||||||
git add X &&
|
git add X &&
|
||||||
chmod a+x A &&
|
test_chmod +x A &&
|
||||||
test_tick &&
|
test_tick &&
|
||||||
git commit -m modechange A X &&
|
git commit -m modechange &&
|
||||||
GIT_TRACE=1 git rebase master
|
GIT_TRACE=1 git rebase master
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -15,21 +15,10 @@ test_expect_success \
|
|||||||
tree=`git write-tree` &&
|
tree=`git write-tree` &&
|
||||||
echo $tree'
|
echo $tree'
|
||||||
|
|
||||||
if [ "$(git config --get core.filemode)" = false ]
|
test_expect_success \
|
||||||
then
|
'chmod' \
|
||||||
say 'filemode disabled on the filesystem, using update-index --chmod=+x'
|
'test_chmod +x rezrov &&
|
||||||
test_expect_success \
|
git diff-index $tree >current'
|
||||||
'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
|
|
||||||
|
|
||||||
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
_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"
|
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
|
||||||
|
@ -16,9 +16,7 @@ test_expect_success setup '
|
|||||||
git checkout -b side &&
|
git checkout -b side &&
|
||||||
|
|
||||||
for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
|
for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
|
||||||
chmod +x elif &&
|
test_chmod +x elif &&
|
||||||
git update-index file elif &&
|
|
||||||
git update-index --chmod=+x elif &&
|
|
||||||
git commit -m "Side changes #1" &&
|
git commit -m "Side changes #1" &&
|
||||||
|
|
||||||
for i in D E F; do echo "$i"; done >>file &&
|
for i in D E F; do echo "$i"; done >>file &&
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
test_description='merge-recursive: handle file mode'
|
test_description='merge-recursive: handle file mode'
|
||||||
. ./test-lib.sh
|
. ./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' '
|
test_expect_success 'mode change in one branch: keep changed version' '
|
||||||
: >file1 &&
|
: >file1 &&
|
||||||
git add file1 &&
|
git add file1 &&
|
||||||
@ -15,8 +12,7 @@ test_expect_success 'mode change in one branch: keep changed version' '
|
|||||||
git add dummy &&
|
git add dummy &&
|
||||||
git commit -m a &&
|
git commit -m a &&
|
||||||
git checkout -b b1 master &&
|
git checkout -b b1 master &&
|
||||||
chmod +x file1 &&
|
test_chmod +x file1 &&
|
||||||
git update-index --chmod=+x file1 &&
|
|
||||||
git commit -m b1 &&
|
git commit -m b1 &&
|
||||||
git checkout a1 &&
|
git checkout a1 &&
|
||||||
git merge-recursive master -- a1 b1 &&
|
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 &&
|
git checkout -b a2 master &&
|
||||||
: >file2 &&
|
: >file2 &&
|
||||||
H=$(git hash-object file2) &&
|
H=$(git hash-object file2) &&
|
||||||
chmod +x file2 &&
|
test_chmod +x file2 &&
|
||||||
git update-index --add --chmod=+x file2 &&
|
|
||||||
git commit -m a2 &&
|
git commit -m a2 &&
|
||||||
git checkout -b b2 master &&
|
git checkout -b b2 master &&
|
||||||
: >file2 &&
|
: >file2 &&
|
||||||
|
@ -63,14 +63,6 @@ gitweb_run () {
|
|||||||
# gitweb.log is left for debugging
|
# 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
|
. ./test-lib.sh
|
||||||
|
|
||||||
perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
|
perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
|
||||||
@ -242,7 +234,7 @@ test_debug 'cat gitweb.log'
|
|||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'commitdiff(0): mode change' \
|
'commitdiff(0): mode change' \
|
||||||
'safe_chmod +x new_file &&
|
'test_chmod +x new_file &&
|
||||||
git commit -a -m "Mode changed." &&
|
git commit -a -m "Mode changed." &&
|
||||||
gitweb_run "p=.git;a=commitdiff"'
|
gitweb_run "p=.git;a=commitdiff"'
|
||||||
test_debug 'cat gitweb.log'
|
test_debug 'cat gitweb.log'
|
||||||
@ -281,7 +273,7 @@ test_debug 'cat gitweb.log'
|
|||||||
test_expect_success \
|
test_expect_success \
|
||||||
'commitdiff(0): mode change and modified' \
|
'commitdiff(0): mode change and modified' \
|
||||||
'echo "New line" >> file2 &&
|
'echo "New line" >> file2 &&
|
||||||
safe_chmod +x file2 &&
|
test_chmod +x file2 &&
|
||||||
git commit -a -m "Mode change and modification." &&
|
git commit -a -m "Mode change and modification." &&
|
||||||
gitweb_run "p=.git;a=commitdiff"'
|
gitweb_run "p=.git;a=commitdiff"'
|
||||||
test_debug 'cat gitweb.log'
|
test_debug 'cat gitweb.log'
|
||||||
@ -308,7 +300,7 @@ test_expect_success \
|
|||||||
'commitdiff(0): renamed, mode change and modified' \
|
'commitdiff(0): renamed, mode change and modified' \
|
||||||
'git mv file3 file2 &&
|
'git mv file3 file2 &&
|
||||||
echo "Propter nomen suum." >> file2 &&
|
echo "Propter nomen suum." >> file2 &&
|
||||||
safe_chmod +x file2 &&
|
test_chmod +x file2 &&
|
||||||
git commit -a -m "File rename, mode change and modification." &&
|
git commit -a -m "File rename, mode change and modification." &&
|
||||||
gitweb_run "p=.git;a=commitdiff"'
|
gitweb_run "p=.git;a=commitdiff"'
|
||||||
test_debug 'cat gitweb.log'
|
test_debug 'cat gitweb.log'
|
||||||
@ -425,10 +417,10 @@ test_expect_success \
|
|||||||
git add 03-new &&
|
git add 03-new &&
|
||||||
git mv 04-rename-from 04-rename-to &&
|
git mv 04-rename-from 04-rename-to &&
|
||||||
echo "Changed" >> 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 &&
|
rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
|
||||||
echo "Changed and have mode changed" > 07-change-mode-change &&
|
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 commit -a -m "Large commit" &&
|
||||||
git checkout master'
|
git checkout master'
|
||||||
|
|
||||||
|
@ -238,6 +238,15 @@ test_merge () {
|
|||||||
git tag "$1"
|
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
|
# You are not expected to call test_ok_ and test_failure_ directly, use
|
||||||
# the text_expect_* functions instead.
|
# the text_expect_* functions instead.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user