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

Re: git-am applies half of a patch

From
Linus Torvalds <torvalds@osdl.org>
Date
Jan 9, 2007, 16:02 UTC
Message-ID
<Pine.LNX.4.64.0701090748020.3661@woody.osdl.org>
In-Reply-To
<45A36D6B.4010303@garzik.org>
On Tue, 9 Jan 2007, Jeff Garzik wrote:
Show 17 quoted lines
>
> I ran
> 
> 	git-am --signoff --utf8 /g/tmp/mbox
> 
> on the attached file, to apply a patch to libata-dev.git#upstream, and it
> wound up only applying a portion of the patch:
> 
> > [jgarzik@pretzel libata-dev]$ git-am --signoff --utf8 /g/tmp/mbox 
> > Applying 'Add pci class code for SATA AHCI'
> > 
> > error: patch fragment without header at line 35: @@ -862,7 +862,7 @@
> > error: patch fragment without header at line 50: @@ -15,6 +15,8 @@
> > Wrote tree 5d6f3a93bea932c950ac880deca173dd3e84dfcc
> > Committed: 317b180bad43133027dc07455f1600f4e8a47d76
> 
> It seems quite bad to apply a patch that git-am KNOWS is incomplete.

It doesn't actually "know" it. What is going on is that the "patch" program generally allows random crap in between multiple patches, and while git-apply is normally stricter than "patch" ever is, git-apply does allow this "garbage between patches" thing too.

Sometimes the garbage is just commentary (some people say things in between patches), but quite often it's also stuff like "Index: " (and in fact, git considers the "diff " line at the head to be "garbage" too, unless it's a native git diff that has the "diff --git" signature).

So what git is actually doing is seeing that you have _garbage_ after the real patch, but then it _warns_ about the garbage containing what looks like a patch fragment. And the reason it's garbage (rather than a real patch) is obviously because your patch was so heavily whitespace-damaged that the header that was supposed to start it wasn't a valid header at all..

But if you'd like to make it fatal, the patch is certainly simple..

Junio - I certainly wouldn't mind making this a fatal error, but it's ultimately your decision.

		Linus
---
diff --git a/builtin-apply.c b/builtin-apply.c
index 1c35837..d3fdf7e 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -811,7 +811,7 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
 			struct fragment dummy;
 			if (parse_fragment_header(line, len, &dummy) < 0)
 				continue;
-			error("patch fragment without header at line %d: %.*s", linenr, (int)len-1, line);
+			die("patch fragment without header at line %d: %.*s", linenr, (int)len-1, line);
 		}
 
 		if (size < len + 6)
Previous: Junio C Hamano
Message 6 of 6 in “git-am applies half of a patch”
  1. Jeff GarzikJan 9, 2007
  2. Junio C HamanoJan 9, 2007
  3. Jeff GarzikJan 9, 2007
  4. Linus TorvaldsJan 9, 2007
  5. Junio C HamanoJan 9, 2007
  6. Linus TorvaldsJan 9, 2007

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.