Skip to content

Commit

Permalink
Fix severe breakage in "git-apply --whitespace=fix"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 25, 2009
1 parent 01ae841 commit 422a82f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions t/t4124-apply-ws-rule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ create_patch () {
index e69de29..8bd6648 100644
--- a/target
+++ b/target
@@ -0,0 +1 @@
@@ -0,0 +1,3 @@
+An empty line follows
+
+A line with trailing whitespace and no newline_
\ No newline at end of file
EOF
}

test_expect_success 'trailing whitespace & no newline at the end of file' '
>target &&
create_patch | git apply --whitespace=fix - &&
grep "newline$" target
create_patch >patch-file &&
git apply --whitespace=fix patch-file &&
grep "newline$" target &&
grep "^$" target
'

test_done
4 changes: 2 additions & 2 deletions ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
* Strip trailing whitespace
*/
if (ws_rule & WS_TRAILING_SPACE) {
if (1 < len && src[len - 1] == '\n') {
if (0 < len && src[len - 1] == '\n') {
add_nl_to_tail = 1;
len--;
if (1 < len && src[len - 1] == '\r') {
if (0 < len && src[len - 1] == '\r') {
add_cr_to_tail = !!(ws_rule & WS_CR_AT_EOL);
len--;
}
Expand Down

0 comments on commit 422a82f

Please sign in to comment.