git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] solving a bug with hunks starting at line 1 in git apply

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jun 1, 2015, 18:20 UTC
Message-ID
<vpq382b47fq.fsf@anie.imag.fr>
In-Reply-To
<87k2vnqrv8.fsf@ensimag.grenoble-inp.fr>
Remi LESPINET <remi.lespinet@ensimag.grenoble-inp.fr> writes:
Show 14 quoted lines
> ======================================================================
> = 2. Correction
> ======================================================================
>
> I see mainly two ways to fix the bug:
>
> ********************************************************************
> * 2.1 first method (the most basic)
> ********************************************************************
>
> The most basic is to change the code so that the special behavior
> only affects the hunks of the form
>
> @@ -1,k +1,m @@
I do not think that this would work in all cases. It seems git apply has
issues with overlapping contexts, not just with hunks starting at line
1. See:

$ cat pre.txt -1 0 10 20 30 40 $ cat p2.diff --- pre.txt +++ pre.txt

@@ -2,2 +2,3 @@
 0
+5
 10
@@ -3,3 +4,3 @@
 10
+15
-20
 30
$ git apply p2.diff
error: patch failed: pre.txt:3
error: pre.txt: patch does not apply
$ patch < p2.diff 
patching file pre.txt
$ cat pre.txt
-1
0
5
10
15
30
40
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Remi Lespinet
Message 9 of 9 in “[RFC] solving a bug with hunks starting at line 1 in git apply”
  1. Remi LESPINETJun 1, 2015
  2. Junio C HamanoJun 1, 2015
  3. Junio C HamanoJun 1, 2015
  4. Matthieu MoyJun 1, 2015
  5. Junio C HamanoJun 1, 2015
  6. Matthieu MoyJun 1, 2015
  7. Junio C HamanoJun 1, 2015
  8. Remi LespinetJun 1, 2015
  9. Matthieu MoyJun 1, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.