Skip to content

Commit d78a122

Browse files
committed
Merge branch 'rs/apply-inaccurate-eof-with-incomplete-line'
"git apply --inaccurate-eof" when used with "--ignore-space-change" triggered an internal sanity check, which has been fixed. * rs/apply-inaccurate-eof-with-incomplete-line: apply: update line lengths for --inaccurate-eof
2 parents c2ed683 + 4855de1 commit d78a122

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

apply.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,8 @@ static int apply_one_fragment(struct apply_state *state,
29532953
newlines.len > 0 && newlines.buf[newlines.len - 1] == '\n') {
29542954
old--;
29552955
strbuf_setlen(&newlines, newlines.len - 1);
2956+
preimage.line_allocated[preimage.nr - 1].len--;
2957+
postimage.line_allocated[postimage.nr - 1].len--;
29562958
}
29572959

29582960
leading = frag->leading;

t/t4107-apply-ignore-whitespace.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,18 @@ test_expect_success 'patch5 fails (--no-ignore-whitespace)' '
178178
test_must_fail git apply --no-ignore-whitespace patch5.patch
179179
'
180180

181+
test_expect_success 'apply --ignore-space-change --inaccurate-eof' '
182+
echo 1 >file &&
183+
git apply --ignore-space-change --inaccurate-eof <<-\EOF &&
184+
diff --git a/file b/file
185+
--- a/file
186+
+++ b/file
187+
@@ -1 +1 @@
188+
-1
189+
+2
190+
EOF
191+
printf 2 >expect &&
192+
test_cmp expect file
193+
'
194+
181195
test_done

0 commit comments

Comments
 (0)