blob: 5cdd76dfa726d32226b1dd625d21d6280125afb7 [file] [log] [blame]
Junio C Hamano1f7903a2009-01-02 02:55:37 -08001#!/bin/sh
2
3test_description='applying patch with mode bits'
4
5. ./test-lib.sh
Johannes Sixt872f3492009-02-27 22:20:57 +01006
Junio C Hamano1f7903a2009-01-02 02:55:37 -08007test_expect_success setup '
8 echo original >file &&
9 git add file &&
10 test_tick &&
11 git commit -m initial &&
12 git tag initial &&
13 echo modified >file &&
14 git diff --stat -p >patch-0.txt &&
15 chmod +x file &&
René Scharfe44e54712017-06-27 19:03:47 +020016 git diff --stat -p >patch-1.txt &&
17 sed "s/^\(new mode \).*/\1/" <patch-1.txt >patch-empty-mode.txt &&
18 sed "s/^\(new mode \).*/\1garbage/" <patch-1.txt >patch-bogus-mode.txt
Junio C Hamano1f7903a2009-01-02 02:55:37 -080019'
20
Johannes Sixt872f3492009-02-27 22:20:57 +010021test_expect_success FILEMODE 'same mode (no index)' '
Junio C Hamano1f7903a2009-01-02 02:55:37 -080022 git reset --hard &&
23 chmod +x file &&
24 git apply patch-0.txt &&
25 test -x file
26'
27
Johannes Sixt872f3492009-02-27 22:20:57 +010028test_expect_success FILEMODE 'same mode (with index)' '
Junio C Hamano1f7903a2009-01-02 02:55:37 -080029 git reset --hard &&
30 chmod +x file &&
31 git add file &&
32 git apply --index patch-0.txt &&
33 test -x file &&
34 git diff --exit-code
35'
36
Johannes Sixt872f3492009-02-27 22:20:57 +010037test_expect_success FILEMODE 'same mode (index only)' '
Junio C Hamano1f7903a2009-01-02 02:55:37 -080038 git reset --hard &&
39 chmod +x file &&
40 git add file &&
41 git apply --cached patch-0.txt &&
42 git ls-files -s file | grep "^100755"
43'
44
Johannes Sixt872f3492009-02-27 22:20:57 +010045test_expect_success FILEMODE 'mode update (no index)' '
Junio C Hamano1f7903a2009-01-02 02:55:37 -080046 git reset --hard &&
47 git apply patch-1.txt &&
48 test -x file
49'
50
Johannes Sixt872f3492009-02-27 22:20:57 +010051test_expect_success FILEMODE 'mode update (with index)' '
Junio C Hamano1f7903a2009-01-02 02:55:37 -080052 git reset --hard &&
53 git apply --index patch-1.txt &&
54 test -x file &&
55 git diff --exit-code
56'
57
Johannes Sixt872f3492009-02-27 22:20:57 +010058test_expect_success FILEMODE 'mode update (index only)' '
Junio C Hamano1f7903a2009-01-02 02:55:37 -080059 git reset --hard &&
60 git apply --cached patch-1.txt &&
61 git ls-files -s file | grep "^100755"
62'
63
René Scharfe44e54712017-06-27 19:03:47 +020064test_expect_success FILEMODE 'empty mode is rejected' '
65 git reset --hard &&
66 test_must_fail git apply patch-empty-mode.txt 2>err &&
67 test_i18ngrep "invalid mode" err
68'
69
70test_expect_success FILEMODE 'bogus mode is rejected' '
71 git reset --hard &&
72 test_must_fail git apply patch-bogus-mode.txt 2>err &&
73 test_i18ngrep "invalid mode" err
74'
75
Junio C Hamano1f7903a2009-01-02 02:55:37 -080076test_done