apply: Allow blank context lines to match beyond EOF
commit51667147be4a5aed6d735d43630ce36b74134eee
authorBjörn Gustavsson <bgustavsson@gmail.com>
Sat, 6 Mar 2010 14:30:42 +0000 (6 15:30 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 7 Mar 2010 07:53:00 +0000 (6 23:53 -0800)
tree72603b99de300d134f236efc6e3959b8ce4e826c
parent24ff4d56cf400126aa93ac9a5b9d8a21afadf3f6
apply: Allow blank context lines to match beyond EOF

"git apply --whitespace=fix" will not always succeed when used
on a series of patches in the following circumstances:

* One patch adds a blank line at the end of a file. (Since
  --whitespace=fix is used, the blank line will *not* be added.)

* The next patch adds non-blank lines after the blank line
  introduced in the first patch. That patch will not apply
  because the blank line that is expected to be found at end
  of the file is no longer there.

A patch series that starts by deleting lines at the end
will fail in a similar way.

Fix this problem by allowing a blank context line at the beginning
of a hunk to match if parts of it falls beyond end of the file.
We still require that at least one non-blank context line match
before the end of the file.

If the --ignore-space-change option is given (as well as the
--whitespace=fix option), blank context lines falling beyond the end
of the file will be copied unchanged to the target file (i.e. they
will have the same line terminators and extra spaces will not be
removed).

Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-apply.c