bash: teach 'git checkout' options
[git] / t / t4129-apply-samemode.sh
1 #!/bin/sh
2
3 test_description='applying patch with mode bits'
4
5 . ./test-lib.sh
6
7 if test "$(git config --bool core.filemode)" = false
8 then
9         say 'filemode disabled on the filesystem'
10 else
11         test_set_prereq FILEMODE
12 fi
13
14 test_expect_success setup '
15         echo original >file &&
16         git add file &&
17         test_tick &&
18         git commit -m initial &&
19         git tag initial &&
20         echo modified >file &&
21         git diff --stat -p >patch-0.txt &&
22         chmod +x file &&
23         git diff --stat -p >patch-1.txt
24 '
25
26 test_expect_success FILEMODE 'same mode (no index)' '
27         git reset --hard &&
28         chmod +x file &&
29         git apply patch-0.txt &&
30         test -x file
31 '
32
33 test_expect_success FILEMODE 'same mode (with index)' '
34         git reset --hard &&
35         chmod +x file &&
36         git add file &&
37         git apply --index patch-0.txt &&
38         test -x file &&
39         git diff --exit-code
40 '
41
42 test_expect_success FILEMODE 'same mode (index only)' '
43         git reset --hard &&
44         chmod +x file &&
45         git add file &&
46         git apply --cached patch-0.txt &&
47         git ls-files -s file | grep "^100755"
48 '
49
50 test_expect_success FILEMODE 'mode update (no index)' '
51         git reset --hard &&
52         git apply patch-1.txt &&
53         test -x file
54 '
55
56 test_expect_success FILEMODE 'mode update (with index)' '
57         git reset --hard &&
58         git apply --index patch-1.txt &&
59         test -x file &&
60         git diff --exit-code
61 '
62
63 test_expect_success FILEMODE 'mode update (index only)' '
64         git reset --hard &&
65         git apply --cached patch-1.txt &&
66         git ls-files -s file | grep "^100755"
67 '
68
69 test_done