Skip to content

Commit 55d867c

Browse files
committed
Merge branch 'jc/whitespace-incomplete-line'
Fix whitespace correction for new-style empty context lines. * jc/whitespace-incomplete-line: apply: fix new-style empty context line triggering incomplete-line check
2 parents d88c8ba + afdb4c6 commit 55d867c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

apply.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,16 @@ static int parse_fragment(struct apply_state *state,
18401840
trailing++;
18411841
check_old_for_crlf(patch, line, len);
18421842
if (!state->apply_in_reverse &&
1843-
state->ws_error_action == correct_ws_error)
1844-
check_whitespace(state, line, len, patch->ws_rule);
1843+
state->ws_error_action == correct_ws_error) {
1844+
const char *test_line = line;
1845+
int test_len = len;
1846+
if (*line == '\n') {
1847+
test_line = " \n";
1848+
test_len = 2;
1849+
}
1850+
check_whitespace(state, test_line, test_len,
1851+
patch->ws_rule);
1852+
}
18451853
break;
18461854
case '-':
18471855
if (!state->apply_in_reverse)

t/t4124-apply-ws-rule.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,22 @@ test_expect_success 'check incomplete lines (setup)' '
561561
git config core.whitespace incomplete-line
562562
'
563563

564+
test_expect_success 'no incomplete context line (not an error)' '
565+
test_when_finished "rm -f sample*-i patch patch-new target" &&
566+
test_write_lines 1 2 3 "" 4 5 >sample-i &&
567+
test_write_lines 1 2 3 "" 0 5 >sample2-i &&
568+
cat sample-i >target &&
569+
git add target &&
570+
cat sample2-i >target &&
571+
git diff-files -p target >patch &&
572+
sed -e "s/^ $//" <patch >patch-new &&
573+
574+
cat sample-i >target &&
575+
git apply --whitespace=fix <patch-new 2>error &&
576+
test_cmp sample2-i target &&
577+
test_must_be_empty error
578+
'
579+
564580
test_expect_success 'incomplete context line (not an error)' '
565581
(test_write_lines 1 2 3 4 5 && printf 6) >sample-i &&
566582
(test_write_lines 1 2 3 0 5 && printf 6) >sample2-i &&

0 commit comments

Comments
 (0)