diff --git a/builtin-apply.c b/builtin-apply.c
index 4eb263ec5807a771b3a61c147b74a6f2f68dddee..20bef1f21d393b0ddf36b8336af85a70c9b8c39c 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.