@@ -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 &&
@@ -336,15 +335,9 @@ test_expect_success 'git add --chmod=[+-]x stages correctly' '
336335 rm -f foo1 &&
337336 echo foo >foo1 &&
338337 git add --chmod=+x foo1 &&
339- case "$(git ls-files --stage foo1)" in
340- 100755" "*foo1) echo pass;;
341- *) echo fail; git ls-files --stage foo1; (exit 1);;
342- esac &&
338+ test_mode_in_index 100755 foo1 &&
343339 git add --chmod=-x foo1 &&
344- case "$(git ls-files --stage foo1)" in
345- 100644" "*foo1) echo pass;;
346- *) echo fail; git ls-files --stage foo1; (exit 1);;
347- esac
340+ test_mode_in_index 100644 foo1
348341'
349342
350343test_expect_success POSIXPERM,SYMLINKS ' git add --chmod=+x with symlinks' '
@@ -353,10 +346,7 @@ test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
353346 rm -f foo2 &&
354347 echo foo >foo2 &&
355348 git add --chmod=+x foo2 &&
356- case "$(git ls-files --stage foo2)" in
357- 100755" "*foo2) echo pass;;
358- *) echo fail; git ls-files --stage foo2; (exit 1);;
359- esac
349+ test_mode_in_index 100755 foo2
360350'
361351
362352test_done
0 commit comments