@matheusbsbs / matheus-bagliano / commits / 422a82f213
Fork 0

Fix severe breakage in "git-apply --whitespace=fix"

735c674 (Trailing whitespace and no newline fix, 2009-07-22) completely broke --whitespace=fix, causing it to lose all the empty lines in a patch. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 25, 2009 at 01:29 UTC 422a82f21370fe38b3e926a83b460bf2b1dd13ab
2 files changed +9 -5
t/t4124-apply-ws-rule.sh
+7 -3
@@ -154,7 +154,9 @@ create_patch () {
154 index e69de29..8bd6648 100644
155 --- a/target
156 +++ b/target
157 - @@ -0,0 +1 @@
157 + @@ -0,0 +1,3 @@
158 + +An empty line follows
159 + +
160 +A line with trailing whitespace and no newline_
161 \ No newline at end of file
162 EOF
@@ -162,8 +164,10 @@ create_patch () {
164
165 test_expect_success 'trailing whitespace & no newline at the end of file' '
166 >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
171 '
172
173 test_done
ws.c
+2 -2
@@ -262,10 +262,10 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
262 * Strip trailing whitespace
263 */
264 if (ws_rule & WS_TRAILING_SPACE) {
265 - if (1 < len && src[len - 1] == '\n') {
265 + if (0 < len && src[len - 1] == '\n') {
266 add_nl_to_tail = 1;
267 len--;
268 - if (1 < len && src[len - 1] == '\r') {
268 + if (0 < len && src[len - 1] == '\r') {
269 add_cr_to_tail = !!(ws_rule & WS_CR_AT_EOL);
270 len--;
271 }