Skip to content

Commit

Permalink
Merge branch 'bg/apply-blank-trailing-context'
Browse files Browse the repository at this point in the history
* bg/apply-blank-trailing-context:
  apply: Allow blank *trailing* context lines to match beyond EOF
  • Loading branch information
gitster committed May 9, 2010
2 parents daa81c4 + 0c3ef98 commit b751157
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 6 additions & 6 deletions builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1866,13 +1866,13 @@ static int match_fragment(struct image *img,
if (match_end && (preimage->nr + try_lno != img->nr))
return 0;
} else if (ws_error_action == correct_ws_error &&
(ws_rule & WS_BLANK_AT_EOF) && match_end) {
(ws_rule & WS_BLANK_AT_EOF)) {
/*
* This hunk that matches at the end extends beyond
* the end of img, and we are removing blank lines
* at the end of the file. This many lines from the
* beginning of the preimage must match with img, and
* the remainder of the preimage must be blank.
* This hunk extends beyond the end of img, and we are
* removing blank lines at the end of the file. This
* many lines from the beginning of the preimage must
* match with img, and the remainder of the preimage
* must be blank.
*/
preimage_limit = img->nr - try_lno;
} else {
Expand Down
12 changes: 12 additions & 0 deletions t/t4124-apply-ws-rule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,18 @@ test_expect_success 'two missing blank lines at end with --whitespace=fix' '
test_cmp one expect
'

test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' '
{ echo a; echo; } >one &&
git add one &&
{ echo b; echo a; echo; } >one &&
cp one expect &&
git diff -- one >patch &&
echo a >one &&
test_must_fail git apply patch &&
git apply --whitespace=fix patch &&
test_cmp one expect
'

test_expect_success 'shrink file with tons of missing blanks at end of file' '
{ echo a; echo b; echo c; } >one &&
cp one no-blank-lines &&
Expand Down

0 comments on commit b751157

Please sign in to comment.