{"thread":{"id":"31036","subject":"Bug: fatal: patch fragment without header at line","startedAt":"2012-07-16T13:36:51Z","lastAt":"2012-07-17T04:21:37Z","messageCount":3,"participants":["tuxdna","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"195121","messageId":"CAK5QfLMs6CMCTtZ3woQfMim1ssYLKEURAMv8+FgqrKJ7otNcnw@mail.gmail.com","threadId":"31036","inReplyTo":null,"subject":"Bug: fatal: patch fragment without header at line","fromName":"tuxdna","fromEmail":"tuxdna@gmail.com","sentAt":"2012-07-16T13:36:51Z","receivedAt":"2012-07-16T13:36:51Z","isPatch":false,"sender":{"key":"tuxdna@gmail.com","avatar":null},"body":"Git version: git-1.7.7.6-1.fc16.x86_64\n\nI am getting an error with a patch that I am applying to a git repository.\nI have created a test case for this issue that I am facing.\n\n$ git apply --check 0001-modified-README.patch\nfatal: patch fragment without header at line 7: @@ -635,9 +635,7 @@\nsome_function()\n\nClearly line 7 appears to be a patch but it isn't. It is the part of\nemail body or the patch context.\nTo my understanding, the patch should always be identified whenever\nthe patch block starts\nwith a \"diff --git\", which is line 21 as below:\n\n     1\tFrom aa3acc563af0422e6a9f4afc432b7fabdf845d81 Mon Sep 17 00:00:00 2001\n     2\tFrom: Saleem Ansari <tuxdna@gmail.com>\n     3\tDate: Mon, 16 Jul 2012 17:42:58 +0530\n     4\tSubject: [PATCH] modified README\n     5\t\n     6\t\n     7\t@@ -635,9 +635,7 @@ some_function()\n     8\t\n     9\t\n    10\t-       # a comment here\n    11\t+       not a comment\n    12\t\n    13\t\n    14\t\n    15\tthats all folks\n    16\t\n    17\t---\n    18\t README |    1 +\n    19\t 1 files changed, 1 insertions(+), 0 deletions(-)\n    20\t\n    21\tdiff --git a/README b/README\n    22\tindex ce01362..d294257 100644\n    23\t--- a/README\n    24\t+++ b/README\n    25\t@@ -1 +1,2 @@\n    26\t hello\n    27\t+this is a readme\n    28\t--\n    29\t1.7.7.6\n    30\t\n\nApart from changing the patch itself, how else can I work-around this problem?\n\nSteps to create and verify the testcase:\n\n# Create a temporary directory\nmkdir /tmp/bug\ncd /tmp/bug\ngit init .\necho \"hello\" > README\ngit commit -m \"Initial commit\"\n\n# create a test branch for verification later\ngit checkout -b test\n\n# make changes into a different branch\ngit checkout -b bugger\necho \"this is a readme\" > README\ngit commit -m \"modified README\"\ngit format-patch HEAD^ # this will generate 0001-modified-README.patch\n# Now inside the patch email body add some random patch which should break\n# or download the attachment ( 0001-modified-README.patch )\n\n/tuxdna\n\n\nFrom aa3acc563af0422e6a9f4afc432b7fabdf845d81 Mon Sep 17 00:00:00 2001\nFrom: Saleem Ansari <tuxdna@gmail.com>\nDate: Mon, 16 Jul 2012 17:42:58 +0530\nSubject: [PATCH] modified README\n\n\n@@ -635,9 +635,7 @@ some_function()\n\n\n-       # a comment here\n+       not a comment\n\n\n\nthats all folks\n\n---\n README |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/README b/README\nindex ce01362..d294257 100644\n--- a/README\n+++ b/README\n@@ -1 +1,2 @@\n hello\n+this is a readme\n-- \n1.7.7.6\n\n"},{"id":"195133","messageId":"7vy5mj39ow.fsf@alter.siamese.dyndns.org","threadId":"31036","inReplyTo":"CAK5QfLMs6CMCTtZ3woQfMim1ssYLKEURAMv8+FgqrKJ7otNcnw@mail.gmail.com","subject":"Re: Bug: fatal: patch fragment without header at line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-16T17:19:43Z","receivedAt":"2012-07-16T17:19:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tuxdna <tuxdna@gmail.com> writes:\n\n> Git version: git-1.7.7.6-1.fc16.x86_64\n>\n> I am getting an error with a patch that I am applying to a git repository.\n> I have created a test case for this issue that I am facing.\n>\n> $ git apply --check 0001-modified-README.patch\n> fatal: patch fragment without header at line 7: @@ -635,9 +635,7 @@\n> some_function()\n>\n> Clearly line 7 appears to be a patch but it isn't. It is the part of\n> email body or the patch context.\n\nYes, but the error detection needs to stay for a more common case in\nwhich the user corrupted the patch by breaking or removing the diff\nheader.\n\nIf you want to quote a patch fragment in your log message, it is\ncommon to indent the part (without removing the \"diff\" header) which\nalso has the benefit of making it stand out in the textual\ndescription, e.g. here is a sample patch fragment\n\n    diff --git a/README b/README\n    index ce01362..d294257 100644\n    --- a/README\n    +++ b/README\n    @@ -1 +1,2 @@\n     hello\n    +this is a readme\n\nand here comes a paragraph in the log message that can be made more\nunderstandable by having such a patch fragment.\n"},{"id":"195188","messageId":"20120717042137.GE20945@sigill.intra.peff.net","threadId":"31036","inReplyTo":"CAK5QfLMs6CMCTtZ3woQfMim1ssYLKEURAMv8+FgqrKJ7otNcnw@mail.gmail.com","subject":"Re: Bug: fatal: patch fragment without header at line","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-07-17T04:21:37Z","receivedAt":"2012-07-17T04:21:37Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jul 16, 2012 at 07:06:51PM +0530, tuxdna wrote:\n\n> Git version: git-1.7.7.6-1.fc16.x86_64\n> \n> I am getting an error with a patch that I am applying to a git repository.\n> I have created a test case for this issue that I am facing.\n> \n> $ git apply --check 0001-modified-README.patch\n> fatal: patch fragment without header at line 7: @@ -635,9 +635,7 @@\n> some_function()\n> \n> Clearly line 7 appears to be a patch but it isn't. It is the part of\n> email body or the patch context.\n> To my understanding, the patch should always be identified whenever\n> the patch block starts\n> with a \"diff --git\", which is line 21 as below:\n\nIt is identified properly when you use \"git am\" to apply your patch. It\nwill use \"git mailinfo\" to split on the \"---\" and feed only the bottom\nhalf to \"git apply\". But as a low-level tool, \"git apply\" looks for a\npatch immediately, and does not know anything about the \"---\" line. It\nis correct to diagnose a possibly broken patch.\n\n> Apart from changing the patch itself, how else can I work-around this problem?\n\nRun \"git am 0001-modified-README.patch\" to parse it correctly. If for\nsome reason you really do not want to make a commit (e.g., you are going\nto squash-apply a bunch of patches together), then either:\n\n  1. Don't use format-patch to generate the patch. Use \"git diff-tree\",\n     which will omit the commit message (which \"git apply\" would just\n     inore anyway).\n\n  2. Use \"git mailinfo\" to split the patch out of the email format\n     generated by format-patch, and then \"git apply\" the result.\n\n-Peff\n"}]}