mirror of
https://github.com/git/git.git
synced 2024-11-01 06:47:52 +01:00
Merge branch 'maint'
* maint: Fix severe breakage in "git-apply --whitespace=fix"
This commit is contained in:
commit
8f5e3ca7d1
2 changed files with 9 additions and 5 deletions
|
@ -154,7 +154,9 @@ create_patch () {
|
||||||
index e69de29..8bd6648 100644
|
index e69de29..8bd6648 100644
|
||||||
--- a/target
|
--- a/target
|
||||||
+++ b/target
|
+++ b/target
|
||||||
@@ -0,0 +1 @@
|
@@ -0,0 +1,3 @@
|
||||||
|
+An empty line follows
|
||||||
|
+
|
||||||
+A line with trailing whitespace and no newline_
|
+A line with trailing whitespace and no newline_
|
||||||
\ No newline at end of file
|
\ No newline at end of file
|
||||||
EOF
|
EOF
|
||||||
|
@ -162,8 +164,10 @@ create_patch () {
|
||||||
|
|
||||||
test_expect_success 'trailing whitespace & no newline at the end of file' '
|
test_expect_success 'trailing whitespace & no newline at the end of file' '
|
||||||
>target &&
|
>target &&
|
||||||
create_patch | git apply --whitespace=fix - &&
|
create_patch >patch-file &&
|
||||||
grep "newline$" target
|
git apply --whitespace=fix patch-file &&
|
||||||
|
grep "newline$" target &&
|
||||||
|
grep "^$" target
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
4
ws.c
4
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
|
* Strip trailing whitespace
|
||||||
*/
|
*/
|
||||||
if (ws_rule & WS_TRAILING_SPACE) {
|
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;
|
add_nl_to_tail = 1;
|
||||||
len--;
|
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);
|
add_cr_to_tail = !!(ws_rule & WS_CR_AT_EOL);
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue