Skip to content

Commit 8f5e3ca

Browse files
committed
Merge branch 'maint'
* maint: Fix severe breakage in "git-apply --whitespace=fix"
2 parents b3601a6 + 422a82f commit 8f5e3ca

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

t/t4124-apply-ws-rule.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,20 @@ create_patch () {
154154
index e69de29..8bd6648 100644
155155
--- a/target
156156
+++ b/target
157-
@@ -0,0 +1 @@
157+
@@ -0,0 +1,3 @@
158+
+An empty line follows
159+
+
158160
+A line with trailing whitespace and no newline_
159161
\ No newline at end of file
160162
EOF
161163
}
162164

163165
test_expect_success 'trailing whitespace & no newline at the end of file' '
164166
>target &&
165-
create_patch | git apply --whitespace=fix - &&
166-
grep "newline$" target
167+
create_patch >patch-file &&
168+
git apply --whitespace=fix patch-file &&
169+
grep "newline$" target &&
170+
grep "^$" target
167171
'
168172

169173
test_done

ws.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
262262
* Strip trailing whitespace
263263
*/
264264
if (ws_rule & WS_TRAILING_SPACE) {
265-
if (1 < len && src[len - 1] == '\n') {
265+
if (0 < len && src[len - 1] == '\n') {
266266
add_nl_to_tail = 1;
267267
len--;
268-
if (1 < len && src[len - 1] == '\r') {
268+
if (0 < len && src[len - 1] == '\r') {
269269
add_cr_to_tail = !!(ws_rule & WS_CR_AT_EOL);
270270
len--;
271271
}

0 commit comments

Comments
 (0)