summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 82d97da)
raw | patch | inline | side by side (parent: 82d97da)
author | Junio C Hamano <gitster@pobox.com> | |
Fri, 4 Sep 2009 08:41:47 +0000 (01:41 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 4 Sep 2009 09:35:24 +0000 (02:35 -0700) |
b94f2ed (builtin-apply.c: make it more line oriented, 2008-01-26) broke
the logic used to detect if a hunk adds blank lines at the end of the
file. With the new code after that commit:
- img holds the contents of the file that the hunk is being applied to;
- preimage has the lines the hunk expects to be in img; and
- postimage has the lines the hunk wants to update the part in img that
corresponds to preimage with.
and we need to compare if the last line of preimage (not postimage)
matches the last line of img to see if the hunk applies at the end of the
file.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
the logic used to detect if a hunk adds blank lines at the end of the
file. With the new code after that commit:
- img holds the contents of the file that the hunk is being applied to;
- preimage has the lines the hunk expects to be in img; and
- postimage has the lines the hunk wants to update the part in img that
corresponds to preimage with.
and we need to compare if the last line of preimage (not postimage)
matches the last line of img to see if the hunk applies at the end of the
file.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-apply.c | patch | blob | history | |
t/t4124-apply-ws-rule.sh | patch | blob | history |
diff --git a/builtin-apply.c b/builtin-apply.c
index 7a1ff041f15cd4e6ce2a5b1d1e3cb668f2f54f5e..5b5bde4f39e9c438a108fa1be0d04c76a379b696 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
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
index f83322e513b96bb90e71ce39340515c6be0db186..6898722f2e2309d04d2875597386e3cc9829b28c 100755 (executable)
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
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