@matheusbsbs / matheus-bagliano / commits / 1f553918a8
Fork 0

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>

Johannes Sixt committed Feb 28, 2009 at 21:12 UTC 1f553918a8482ea792e8cd4d5d2c75fe60f68aae
7 files changed +24 -43
t/t1410-reflog.sh
+1 -3
@@ -70,9 +70,7 @@ test_expect_success setup '
70 E=`git rev-parse --verify HEAD:A/B/E` &&
71 check_fsck &&
72
73 - chmod +x C &&
74 - ( test "`git config --bool core.filemode`" != false ||
75 - echo executable >>C ) &&
73 + test_chmod +x C &&
74 git add C &&
75 test_tick && git commit -m dragon &&
76 L=`git rev-parse --verify HEAD` &&
t/t3400-rebase.sh
+2 -2
@@ -83,9 +83,9 @@ test_expect_success 'rebase a single mode change' '
83 git checkout -b modechange HEAD^ &&
84 echo 1 > X &&
85 git add X &&
86 - chmod a+x A &&
86 + test_chmod +x A &&
87 test_tick &&
88 - git commit -m modechange A X &&
88 + git commit -m modechange &&
89 GIT_TRACE=1 git rebase master
90 '
91
t/t4006-diff-mode.sh
+4 -15
@@ -15,21 +15,10 @@ test_expect_success \
15 tree=`git write-tree` &&
16 echo $tree'
17
18 -if [ "$(git config --get core.filemode)" = false ]
19 -then
20 - say 'filemode disabled on the filesystem, using update-index --chmod=+x'
21 - test_expect_success \
22 - 'git update-index --chmod=+x' \
23 - 'git update-index rezrov &&
24 - git update-index --chmod=+x rezrov &&
25 - git diff-index $tree >current'
26 -else
27 - test_expect_success \
28 - 'chmod' \
29 - 'chmod +x rezrov &&
30 - git update-index rezrov &&
31 - git diff-index $tree >current'
32 -fi
18 +test_expect_success \
19 + 'chmod' \
20 + 'test_chmod +x rezrov &&
21 + git diff-index $tree >current'
22
23 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
24 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
t/t4014-format-patch.sh
+1 -3
@@ -16,9 +16,7 @@ test_expect_success setup '
16 git checkout -b side &&
17
18 for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
19 - chmod +x elif &&
20 - git update-index file elif &&
21 - git update-index --chmod=+x elif &&
19 + test_chmod +x elif &&
20 git commit -m "Side changes #1" &&
21
22 for i in D E F; do echo "$i"; done >>file &&
t/t6031-merge-recursive.sh
+2 -7
@@ -3,9 +3,6 @@
3 test_description='merge-recursive: handle file mode'
4 . ./test-lib.sh
5
6 -# Note that we follow "chmod +x F" with "update-index --chmod=+x F" to
7 -# help filesystems that do not have the executable bit.
8 -
6 test_expect_success 'mode change in one branch: keep changed version' '
7 : >file1 &&
8 git add file1 &&
@@ -15,8 +12,7 @@ test_expect_success 'mode change in one branch: keep changed version' '
12 git add dummy &&
13 git commit -m a &&
14 git checkout -b b1 master &&
18 - chmod +x file1 &&
19 - git update-index --chmod=+x file1 &&
15 + test_chmod +x file1 &&
16 git commit -m b1 &&
17 git checkout a1 &&
18 git merge-recursive master -- a1 b1 &&
@@ -28,8 +24,7 @@ test_expect_success 'mode change in both branches: expect conflict' '
24 git checkout -b a2 master &&
25 : >file2 &&
26 H=$(git hash-object file2) &&
31 - chmod +x file2 &&
32 - git update-index --add --chmod=+x file2 &&
27 + test_chmod +x file2 &&
28 git commit -m a2 &&
29 git checkout -b b2 master &&
30 : >file2 &&
t/t9500-gitweb-standalone-no-errors.sh
+5 -13
@@ -63,14 +63,6 @@ gitweb_run () {
63 # gitweb.log is left for debugging
64 }
65
66 -safe_chmod () {
67 - chmod "$1" "$2" &&
68 - if [ "$(git config --get core.filemode)" = false ]
69 - then
70 - git update-index --chmod="$1" "$2"
71 - fi
72 -}
73 -
66 . ./test-lib.sh
67
68 perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
@@ -242,7 +234,7 @@ test_debug 'cat gitweb.log'
234
235 test_expect_success \
236 'commitdiff(0): mode change' \
245 - 'safe_chmod +x new_file &&
237 + 'test_chmod +x new_file &&
238 git commit -a -m "Mode changed." &&
239 gitweb_run "p=.git;a=commitdiff"'
240 test_debug 'cat gitweb.log'
@@ -281,7 +273,7 @@ test_debug 'cat gitweb.log'
273 test_expect_success \
274 'commitdiff(0): mode change and modified' \
275 'echo "New line" >> file2 &&
284 - safe_chmod +x file2 &&
276 + test_chmod +x file2 &&
277 git commit -a -m "Mode change and modification." &&
278 gitweb_run "p=.git;a=commitdiff"'
279 test_debug 'cat gitweb.log'
@@ -308,7 +300,7 @@ test_expect_success \
300 'commitdiff(0): renamed, mode change and modified' \
301 'git mv file3 file2 &&
302 echo "Propter nomen suum." >> file2 &&
311 - safe_chmod +x file2 &&
303 + test_chmod +x file2 &&
304 git commit -a -m "File rename, mode change and modification." &&
305 gitweb_run "p=.git;a=commitdiff"'
306 test_debug 'cat gitweb.log'
@@ -425,10 +417,10 @@ test_expect_success \
417 git add 03-new &&
418 git mv 04-rename-from 04-rename-to &&
419 echo "Changed" >> 04-rename-to &&
428 - safe_chmod +x 05-mode-change &&
420 + test_chmod +x 05-mode-change &&
421 rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink &&
422 echo "Changed and have mode changed" > 07-change-mode-change &&
431 - safe_chmod +x 07-change-mode-change &&
423 + test_chmod +x 07-change-mode-change &&
424 git commit -a -m "Large commit" &&
425 git checkout master'
426
t/test-lib.sh
+9
@@ -238,6 +238,15 @@ test_merge () {
238 git tag "$1"
239 }
240
241 +# This function helps systems where core.filemode=false is set.
242 +# Use it instead of plain 'chmod +x' to set or unset the executable bit
243 +# of a file in the working directory and add it to the index.
244 +
245 +test_chmod () {
246 + chmod "$@" &&
247 + git update-index --add "--chmod=$@"
248 +}
249 +
250 # You are not expected to call test_ok_ and test_failure_ directly, use
251 # the text_expect_* functions instead.
252