summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 01ae841)
raw | patch | inline | side by side (parent: 01ae841)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 25 Jul 2009 08:29:20 +0000 (01:29 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 25 Jul 2009 08:29:20 +0000 (01:29 -0700) |
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>
broke --whitespace=fix, causing it to lose all the empty lines in a patch.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4124-apply-ws-rule.sh | patch | blob | history | |
ws.c | patch | blob | history |
index 5698a9a7365456046ebdab9f783d0cf6fce95f14..fac2093d7f20d502f41f895d2ccdfccd5e639e2b 100755 (executable)
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
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
index 8d855b7fd5d0a74da04acfdd3e78182cc798b6fe..59d0883c1f3a46edcbb2e45b172c9eac3b9d5e35 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -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--;
}