@@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'
77
88. ./test-lib.sh
99
10+ # Test the file mode "$1" of the file "$2" in the index.
11+ test_mode_in_index () {
12+ case " $( git ls-files -s " $2 " ) " in
13+ " $1 " * " $2 " )
14+ echo pass
15+ ;;
16+ * )
17+ echo fail
18+ git ls-files -s " $2 "
19+ return 1
20+ ;;
21+ esac
22+ }
23+
1024test_expect_success \
1125 ' Test of git add' \
1226 ' touch foo && git add foo'
@@ -25,18 +39,12 @@ test_expect_success \
2539 echo foo >xfoo1 &&
2640 chmod 755 xfoo1 &&
2741 git add xfoo1 &&
28- case "$(git ls-files --stage xfoo1)" in
29- 100644" "*xfoo1) echo pass;;
30- *) echo fail; git ls-files --stage xfoo1; (exit 1);;
31- esac'
42+ test_mode_in_index 100644 xfoo1'
3243
3344test_expect_success ' git add: filemode=0 should not get confused by symlink' '
3445 rm -f xfoo1 &&
3546 test_ln_s_add foo xfoo1 &&
36- case "$(git ls-files --stage xfoo1)" in
37- 120000" "*xfoo1) echo pass;;
38- *) echo fail; git ls-files --stage xfoo1; (exit 1);;
39- esac
47+ test_mode_in_index 120000 xfoo1
4048'
4149
4250test_expect_success \
@@ -45,28 +53,19 @@ test_expect_success \
4553 echo foo >xfoo2 &&
4654 chmod 755 xfoo2 &&
4755 git update-index --add xfoo2 &&
48- case "$(git ls-files --stage xfoo2)" in
49- 100644" "*xfoo2) echo pass;;
50- *) echo fail; git ls-files --stage xfoo2; (exit 1);;
51- esac'
56+ test_mode_in_index 100644 xfoo2'
5257
5358test_expect_success ' git add: filemode=0 should not get confused by symlink' '
5459 rm -f xfoo2 &&
5560 test_ln_s_add foo xfoo2 &&
56- case "$(git ls-files --stage xfoo2)" in
57- 120000" "*xfoo2) echo pass;;
58- *) echo fail; git ls-files --stage xfoo2; (exit 1);;
59- esac
61+ test_mode_in_index 120000 xfoo2
6062'
6163
6264test_expect_success \
6365 ' git update-index --add: Test that executable bit is not used...' \
6466 ' git config core.filemode 0 &&
6567 test_ln_s_add xfoo2 xfoo3 && # runs git update-index --add
66- case "$(git ls-files --stage xfoo3)" in
67- 120000" "*xfoo3) echo pass;;
68- *) echo fail; git ls-files --stage xfoo3; (exit 1);;
69- esac'
68+ test_mode_in_index 120000 xfoo3'
7069
7170test_expect_success ' .gitignore test setup' '
7271 echo "*.ig" >.gitignore &&
@@ -332,34 +331,22 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
332331 test_i18ncmp expect.err actual.err
333332'
334333
335- test_expect_success ' git add --chmod=+x stages a non-executable file with +x' '
334+ test_expect_success ' git add --chmod=[+-]x stages correctly' '
335+ rm -f foo1 &&
336336 echo foo >foo1 &&
337337 git add --chmod=+x foo1 &&
338- case "$(git ls-files --stage foo1)" in
339- 100755" "*foo1) echo pass;;
340- *) echo fail; git ls-files --stage foo1; (exit 1);;
341- esac
342- '
343-
344- test_expect_success ' git add --chmod=-x stages an executable file with -x' '
345- echo foo >xfoo1 &&
346- chmod 755 xfoo1 &&
347- git add --chmod=-x xfoo1 &&
348- case "$(git ls-files --stage xfoo1)" in
349- 100644" "*xfoo1) echo pass;;
350- *) echo fail; git ls-files --stage xfoo1; (exit 1);;
351- esac
338+ test_mode_in_index 100755 foo1 &&
339+ git add --chmod=-x foo1 &&
340+ test_mode_in_index 100644 foo1
352341'
353342
354343test_expect_success POSIXPERM,SYMLINKS ' git add --chmod=+x with symlinks' '
355344 git config core.filemode 1 &&
356345 git config core.symlinks 1 &&
346+ rm -f foo2 &&
357347 echo foo >foo2 &&
358348 git add --chmod=+x foo2 &&
359- case "$(git ls-files --stage foo2)" in
360- 100755" "*foo2) echo pass;;
361- *) echo fail; git ls-files --stage foo2; (exit 1);;
362- esac
349+ test_mode_in_index 100755 foo2
363350'
364351
365352test_done
0 commit comments