Skip to content

Commit b751157

Browse files
committed
Merge branch 'bg/apply-blank-trailing-context'
* bg/apply-blank-trailing-context: apply: Allow blank *trailing* context lines to match beyond EOF
2 parents daa81c4 + 0c3ef98 commit b751157

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

builtin/apply.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,13 +1866,13 @@ static int match_fragment(struct image *img,
18661866
if (match_end && (preimage->nr + try_lno != img->nr))
18671867
return 0;
18681868
} else if (ws_error_action == correct_ws_error &&
1869-
(ws_rule & WS_BLANK_AT_EOF) && match_end) {
1869+
(ws_rule & WS_BLANK_AT_EOF)) {
18701870
/*
1871-
* This hunk that matches at the end extends beyond
1872-
* the end of img, and we are removing blank lines
1873-
* at the end of the file. This many lines from the
1874-
* beginning of the preimage must match with img, and
1875-
* the remainder of the preimage must be blank.
1871+
* This hunk extends beyond the end of img, and we are
1872+
* removing blank lines at the end of the file. This
1873+
* many lines from the beginning of the preimage must
1874+
* match with img, and the remainder of the preimage
1875+
* must be blank.
18761876
*/
18771877
preimage_limit = img->nr - try_lno;
18781878
} else {

t/t4124-apply-ws-rule.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ test_expect_success 'two missing blank lines at end with --whitespace=fix' '
330330
test_cmp one expect
331331
'
332332

333+
test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' '
334+
{ echo a; echo; } >one &&
335+
git add one &&
336+
{ echo b; echo a; echo; } >one &&
337+
cp one expect &&
338+
git diff -- one >patch &&
339+
echo a >one &&
340+
test_must_fail git apply patch &&
341+
git apply --whitespace=fix patch &&
342+
test_cmp one expect
343+
'
344+
333345
test_expect_success 'shrink file with tons of missing blanks at end of file' '
334346
{ echo a; echo b; echo c; } >one &&
335347
cp one no-blank-lines &&

0 commit comments

Comments
 (0)