102
)
103
'
104
105
+test_file_mode_staged () {
106
+ git ls-files --stage -- "$2" >ls-files-output &&
107
+ test_grep "^$1 " ls-files-output
108
+}
109
+
110
+test_file_mode_HEAD () {
111
+ git ls-tree HEAD -- "$2" >ls-tree-output &&
112
+ test_grep "^$1 " ls-tree-output
113
+}
114
+
115
test_expect_success 'git apply respects core.fileMode' '
116
test_config core.fileMode false &&
117
echo true >script.sh &&
118
git add --chmod=+x script.sh &&
109
- git ls-files -s script.sh >ls-files-output &&
110
- test_grep "^100755" ls-files-output &&
119
+ test_file_mode_staged 100755 script.sh &&
120
test_tick && git commit -m "Add script" &&
112
- git ls-tree -r HEAD script.sh >ls-tree-output &&
113
- test_grep "^100755" ls-tree-output &&
121
+ test_file_mode_HEAD 100755 script.sh &&
122
123
echo true >>script.sh &&
124
test_tick && git commit -m "Modify script" script.sh &&
134
test_grep ! "has type 100644, expected 100755" err &&
135
136
git apply --cached patch 2>err &&
129
- test_grep ! "has type 100644, expected 100755" err
137
+ test_grep ! "has type 100644, expected 100755" err &&
138
+ git reset --hard
139
+'
140
+
141
+test_expect_success 'setup: git apply [--reverse] warns about incorrect file modes' '
142
+ test_config core.fileMode false &&
143
+
144
+ >mode_test &&
145
+ git add --chmod=-x mode_test &&
146
+ test_file_mode_staged 100644 mode_test &&
147
+ test_tick && git commit -m "add mode_test" &&
148
+ test_file_mode_HEAD 100644 mode_test &&
149
+ git tag mode_test_forward_initial &&
150
+
151
+ echo content >>mode_test &&
152
+ test_tick && git commit -m "append to mode_test" mode_test &&
153
+ test_file_mode_HEAD 100644 mode_test &&
154
+ git tag mode_test_reverse_initial &&
155
+
156
+ git format-patch -1 --stdout >patch &&
157
+ test_grep "^index .* 100644$" patch
158
+'
159
+
160
+test_expect_success 'git apply warns about incorrect file modes' '
161
+ test_config core.fileMode false &&
162
+ git reset --hard mode_test_forward_initial &&
163
+
164
+ git add --chmod=+x mode_test &&
165
+ test_file_mode_staged 100755 mode_test &&
166
+ test_tick && git commit -m "make mode_test executable" &&
167
+ test_file_mode_HEAD 100755 mode_test &&
168
+
169
+ git apply --index patch 2>err &&
170
+ test_grep "has type 100755, expected 100644" err &&
171
+ test_file_mode_staged 100755 mode_test &&
172
+ test_tick && git commit -m "redo: append to mode_test" &&
173
+ test_file_mode_HEAD 100755 mode_test
174
+'
175
+
176
+test_expect_success 'git apply --reverse warns about incorrect file modes' '
177
+ test_config core.fileMode false &&
178
+ git reset --hard mode_test_reverse_initial &&
179
+
180
+ git add --chmod=+x mode_test &&
181
+ test_file_mode_staged 100755 mode_test &&
182
+ test_tick && git commit -m "make mode_test executable" &&
183
+ test_file_mode_HEAD 100755 mode_test &&
184
+
185
+ git apply --index --reverse patch 2>err &&
186
+ test_grep "has type 100755, expected 100644" err &&
187
+ test_file_mode_staged 100755 mode_test &&
188
+ test_tick && git commit -m "undo: append to mode_test" &&
189
+ test_file_mode_HEAD 100755 mode_test
190
'
191
192
test_expect_success POSIXPERM 'patch mode for new file is canonicalized' '