@@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'
7
7
8
8
. ./test-lib.sh
9
9
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
+
10
24
test_expect_success \
11
25
' Test of git add' \
12
26
' touch foo && git add foo'
@@ -25,18 +39,12 @@ test_expect_success \
25
39
echo foo >xfoo1 &&
26
40
chmod 755 xfoo1 &&
27
41
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'
32
43
33
44
test_expect_success ' git add: filemode=0 should not get confused by symlink' '
34
45
rm -f xfoo1 &&
35
46
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
40
48
'
41
49
42
50
test_expect_success \
@@ -45,28 +53,19 @@ test_expect_success \
45
53
echo foo >xfoo2 &&
46
54
chmod 755 xfoo2 &&
47
55
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'
52
57
53
58
test_expect_success ' git add: filemode=0 should not get confused by symlink' '
54
59
rm -f xfoo2 &&
55
60
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
60
62
'
61
63
62
64
test_expect_success \
63
65
' git update-index --add: Test that executable bit is not used...' \
64
66
' git config core.filemode 0 &&
65
67
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'
70
69
71
70
test_expect_success ' .gitignore test setup' '
72
71
echo "*.ig" >.gitignore &&
@@ -336,15 +335,9 @@ test_expect_success 'git add --chmod=[+-]x stages correctly' '
336
335
rm -f foo1 &&
337
336
echo foo >foo1 &&
338
337
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 &&
343
339
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
348
341
'
349
342
350
343
test_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' '
353
346
rm -f foo2 &&
354
347
echo foo >foo2 &&
355
348
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
360
350
'
361
351
362
352
test_done
0 commit comments