diff --git a/builtin-apply.c b/builtin-apply.c
index 2216a0bf7cd53adc31346f66a3b9786a1d688bad..47261e10fb3901f3b99861020762e63856ee2d60 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
/*
* A hunk to change lines at the beginning would begin with
* @@ -1,L +N,M @@
+ * but we need to be careful. -U0 that inserts before the second
+ * line also has this pattern.
*
* And a hunk to add to an empty file would begin with
* @@ -0,0 +N,M @@
* In other words, a hunk that is (frag->oldpos <= 1) with or
* without leading context must match at the beginning.
*/
- match_beginning = frag->oldpos <= 1;
+ match_beginning = (!frag->oldpos ||
+ (frag->oldpos == 1 && !unidiff_zero));
/*
* A hunk without trailing lines must match at the end.