diff options
-rw-r--r-- | builtin-apply.c | 2 | ||||
-rwxr-xr-x | t/t4124-apply-ws-rule.sh | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/builtin-apply.c b/builtin-apply.c index 7a1ff041f..5b5bde4f3 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2069,7 +2069,7 @@ static int apply_one_fragment(struct image *img, struct fragment *frag, if (applied_pos >= 0) { if (ws_error_action == correct_ws_error && new_blank_lines_at_end && - postimage.nr + applied_pos == img->nr) { + preimage.nr + applied_pos == img->nr) { /* * If the patch application adds blank lines * at the end, and if the patch applies at the diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index f83322e51..6898722f2 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -148,4 +148,33 @@ do done done + +test_expect_success 'blank at EOF with --whitespace=fix (1)' ' + : these can fail depending on what we did before + git config --unset core.whitespace + rm -f .gitattributes + + { echo a; echo b; echo c; } >one && + git add one && + { echo a; echo b; echo c; } >expect && + { cat expect; echo; } >one && + git diff -- one >patch && + + git checkout one && + git apply --whitespace=fix patch && + test_cmp expect one +' + +test_expect_success 'blank at EOF with --whitespace=fix (2)' ' + { echo a; echo b; echo c; } >one && + git add one && + { echo a; echo c; } >expect && + { cat expect; echo; echo; } >one && + git diff -- one >patch && + + git checkout one && + git apply --whitespace=fix patch && + test_cmp expect one +' + test_done |