@@ -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 &&
@@ -332,34 +331,22 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
332
331
test_i18ncmp expect.err actual.err
333
332
'
334
333
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 &&
336
336
echo foo >foo1 &&
337
337
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
352
341
'
353
342
354
343
test_expect_success POSIXPERM,SYMLINKS ' git add --chmod=+x with symlinks' '
355
344
git config core.filemode 1 &&
356
345
git config core.symlinks 1 &&
346
+ rm -f foo2 &&
357
347
echo foo >foo2 &&
358
348
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
363
350
'
364
351
365
352
test_done
0 commit comments