summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-07-25 08:29:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-07-25 08:29:20 (GMT)
commit422a82f21370fe38b3e926a83b460bf2b1dd13ab (patch)
tree744e121cdc79db2c8243555929e240aa170a187c
parent01ae841ccf3aa5d5331a4e6aed6122fee6617740 (diff)
downloadgit-422a82f21370fe38b3e926a83b460bf2b1dd13ab.zip
git-422a82f21370fe38b3e926a83b460bf2b1dd13ab.tar.gz
git-422a82f21370fe38b3e926a83b460bf2b1dd13ab.tar.bz2
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>
-rwxr-xr-xt/t4124-apply-ws-rule.sh10
-rw-r--r--ws.c4
2 files changed, 9 insertions, 5 deletions
diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
index 5698a9a..fac2093 100755
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
@@ -154,7 +154,9 @@ 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
@@ -162,8 +164,10 @@ create_patch () {
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
diff --git a/ws.c b/ws.c
index 8d855b7..59d0883 100644
--- 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--;
}