{"thread":{"id":"41161","subject":"git format-patch on empty commit","startedAt":"2016-01-11T14:19:52Z","lastAt":"2016-01-11T23:47:46Z","messageCount":5,"participants":["pedro rijo","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"275643","messageId":"CAPMsMoDOqWD+a1pj6BO-QgnknJu+JwnZgefJ=MyP8rEwZQGiPQ@mail.gmail.com","threadId":"41161","inReplyTo":null,"subject":"git format-patch on empty commit","fromName":"pedro rijo","fromEmail":"pedrorijo91@gmail.com","sentAt":"2016-01-11T14:19:52Z","receivedAt":"2016-01-11T14:19:52Z","isPatch":false,"sender":{"key":"pedrorijo91@gmail.com","avatar":"https://gravatar.com/avatar/a3f4c97ae763402c3ffc08abfec39ef86f6040e34cc9c2a28d36ed10a7a70c91?d=mp&s=160"},"body":"Hi all,\n\nCouldn't find any explanation on git docs on this issue:\n\nIf I create a dummy commit, with some dummy diff, I get a normal patch\nwhen I run\n\n$ git format-patch -1 -o outgoing/ -p -k\n\nbut if the last commit is an empty commit, generated by\n\n$ git commit --allow-empty \"Some commit message\"\n\nthen the output of the format patch will be an empty patch. If the\nfirst case produces something like this:\n\n>From 08cfdb2994554d834b89309ca96d9bf513e26a90 Mon Sep 17 00:00:00 2001\nFrom: pedrorijo91 <pedrorijo91@gmail.com>\nDate: Fri, 8 Jan 2016 12:44:57 +0000\nSubject: dummy commit\n\n\ndiff --git a/lol.txt b/lol.txt\nnew file mode 100644\nindex 0000000..f944b38\n--- /dev/null\n+++ b/lol.txt\n@@ -0,0 +1 @@\n+:)\n--\n2.5.4 (Apple Git-61)\n\n\n\nthen the second case shouldn't generate something like this instead ?\n\n>From 2d486f25c48780e2e132047e681929fcccb7e60c Mon Sep 17 00:00:00 2001\nFrom: pedrorijo91 <pedrorijo91@gmail.com>\nDate: Fri Jan 8 12:43:55 2016 +0000\nSubject: Some commit message\n\n\n2.5.4 (Apple Git-61)\n\nThanks,\nPedro Rijo\n"},{"id":"275705","messageId":"20160111205347.GA14535@sigill.intra.peff.net","threadId":"41161","inReplyTo":"CAPMsMoDOqWD+a1pj6BO-QgnknJu+JwnZgefJ=MyP8rEwZQGiPQ@mail.gmail.com","subject":"Re: git format-patch on empty commit","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-11T20:53:47Z","receivedAt":"2016-01-11T20:53:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 11, 2016 at 02:19:52PM +0000, pedro rijo wrote:\n\n> Couldn't find any explanation on git docs on this issue:\n> \n> If I create a dummy commit, with some dummy diff, I get a normal patch\n> when I run\n> \n> $ git format-patch -1 -o outgoing/ -p -k\n> \n> but if the last commit is an empty commit, generated by\n> \n> $ git commit --allow-empty \"Some commit message\"\n> \n> then the output of the format patch will be an empty patch. If the\n> first case produces something like this:\n\nI'm not sure if this is a bug or not.\n\nIn the beginning, git's revision-traversal machinery generally does not\nshow commits which have no diff. Over the years, commands like \"git log\"\nlearned to set the \"always_show_header\" option to show even empty\ncommits. But format-patch never did.\n\nIt's pretty easy to do:\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex e00cea7..f132ce7 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1283,6 +1283,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \trev.commit_format = CMIT_FMT_EMAIL;\n \trev.verbose_header = 1;\n \trev.diff = 1;\n+\trev.always_show_header = 1;\n \trev.max_parents = 1;\n \tDIFF_OPT_SET(&rev.diffopt, RECURSIVE);\n \trev.subject_prefix = fmt_patch_subject_prefix;\n\nSo on the one hand, it is probably better not to silently omit commits,\nand it would make format-patch consistent with log and other commands.\nAnd what is produced now is somewhat nonsensical. For \"format-patch\n--stdout\", omitting the header is OK; we just skip the commit entirely.\nBut for writing patches to individual files, you end up with an empty\nfile!\n\nOn the other hand, the point of format-patch is generally to feed the\noutput to \"git am\". And I don't think \"am\" handles such empty patches\nvery well (it complains with \"Patch is empty. Was it split wrong?\", and\nthere's no way to say \"no, really, just apply the empty commit\").\n\nSo even if you generated such patches, I'm not sure what you would do\nwith them.\n\nI'd be more sympathetic to a patch like the one above if \"am\" also\nlearned about empty commits (even if it required the user to say \"empty\ncommits are OK, as we already do for \"commit\" and some other commands).\nNote that the patch above also seems to trigger a test failure in t3421\n(which is a rebase test, and rebase builds on \"format-patch | am\"). That\nwould need to be investigated, too. I'm not sure if there's a subtle\ncase I'm missing, or if the test script is simply a little too strict.\n\n-Peff\n"},{"id":"275708","messageId":"xmqqegdnx1xx.fsf@gitster.mtv.corp.google.com","threadId":"41161","inReplyTo":"20160111205347.GA14535@sigill.intra.peff.net","subject":"Re: git format-patch on empty commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-11T21:04:42Z","receivedAt":"2016-01-11T21:04:42Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Mon, Jan 11, 2016 at 02:19:52PM +0000, pedro rijo wrote:\n>\n>> Couldn't find any explanation on git docs on this issue:\n>> \n>> If I create a dummy commit, with some dummy diff, I get a normal patch\n>> when I run\n>> \n>> $ git format-patch -1 -o outgoing/ -p -k\n>> \n>> but if the last commit is an empty commit, generated by\n>> \n>> $ git commit --allow-empty \"Some commit message\"\n>> \n>> then the output of the format patch will be an empty patch. If the\n>> first case produces something like this:\n>\n> I'm not sure if this is a bug or not.\n>\n> In the beginning, git's revision-traversal machinery generally does not\n> show commits which have no diff. Over the years, commands like \"git log\"\n> learned to set the \"always_show_header\" option to show even empty\n> commits. But format-patch never did.\n\nThe patch based workflow support is geared towards helping the\nrecipient of the patches a lot more than the contributors, and to\nprevent mistakes while applying the patches, \"am\" would stop when it\nsees such an empty e-mail as you saw (in the later part of message I\nam not quoting).  After all, a \"format-patch\" output that does not\nhave any patch would be indistinguishable from discussion e-mail\nmessages and the recipient would not want to end up with no-op\ncommits that record such messages.\n\nSo I think skipping no-op commit from the output was done pretty\nmuch deliberately and it is definitely not a bug.  I however do not\nthink it is incorrect to say that it is a lack of feature that\nnobody so far found necessary or beneficial.\n\nI would not refuse to consider adding a new option to \"format-patch\"\nto emit such a no-op message, and add a \"having no patch is OK, just\nrecord a no-op commit\" option to \"am\", though.  But I do not see a\nclear benefit from such change--it sounds more like a set of\n\"because we could\" not \"because we need to\" changes to me.\n\nThanks.\n"},{"id":"275709","messageId":"20160111210915.GA21173@sigill.intra.peff.net","threadId":"41161","inReplyTo":"xmqqegdnx1xx.fsf@gitster.mtv.corp.google.com","subject":"Re: git format-patch on empty commit","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-01-11T21:09:15Z","receivedAt":"2016-01-11T21:09:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 11, 2016 at 01:04:42PM -0800, Junio C Hamano wrote:\n\n> So I think skipping no-op commit from the output was done pretty\n> much deliberately and it is definitely not a bug.  I however do not\n> think it is incorrect to say that it is a lack of feature that\n> nobody so far found necessary or beneficial.\n> \n> I would not refuse to consider adding a new option to \"format-patch\"\n> to emit such a no-op message, and add a \"having no patch is OK, just\n> record a no-op commit\" option to \"am\", though.  But I do not see a\n> clear benefit from such change--it sounds more like a set of\n> \"because we could\" not \"because we need to\" changes to me.\n\nI think we are more or less on the same page. To me it is less \"because\nwe could\" but that some people seem to find empty commits useful in\ntheir workflow (which is why we have \"commit --allow-empty\"), and if you\nuse such a workflow, it is probably reasonable for \"format-patch | am\"\nor \"rebase\" to be trusted to preserve the history (at least with an\noption).\n\nI do not use such workflows myself[1], so I will leave open the question\nof whether they have a benefit. :)\n\n-Peff\n\n[1] Though I will confess to finding \"commit --allow-empty\" quite useful\n    when debugging.\n"},{"id":"275725","messageId":"CAPMsMoBp6wdmHsyrG2yMmqSy92R2_Ne-5Kbz-6VFVhLJO_u8mg@mail.gmail.com","threadId":"41161","inReplyTo":"xmqqegdnx1xx.fsf@gitster.mtv.corp.google.com","subject":"Re: git format-patch on empty commit","fromName":"pedro rijo","fromEmail":"pedrorijo91@gmail.com","sentAt":"2016-01-11T23:47:46Z","receivedAt":"2016-01-11T23:47:46Z","isPatch":false,"sender":{"key":"pedrorijo91@gmail.com","avatar":"https://gravatar.com/avatar/a3f4c97ae763402c3ffc08abfec39ef86f6040e34cc9c2a28d36ed10a7a70c91?d=mp&s=160"},"body":"To be honest I've been playing a bit with some git features that I've\nnever explored, and was trying to create a fairly simple 'email CLI'\nupon git send-email and other git commands (just because git can) just\nfor the fun.\n\nJust like you said, there's seems not be a 'clear benefit from such\nchange--it sounds more like a set of\n\"because we could\" not \"because we need to\" changes'. I was more\ncurious to understand this git behavior than asking to fix the\nbug/implement the feature, so please feel free not to implement this.\n\nThanks,\nPedro Rijo\n\n2016-01-11 21:04 GMT+00:00 Junio C Hamano <gitster@pobox.com>:\n> Jeff King <peff@peff.net> writes:\n>\n>> On Mon, Jan 11, 2016 at 02:19:52PM +0000, pedro rijo wrote:\n>>\n>>> Couldn't find any explanation on git docs on this issue:\n>>>\n>>> If I create a dummy commit, with some dummy diff, I get a normal patch\n>>> when I run\n>>>\n>>> $ git format-patch -1 -o outgoing/ -p -k\n>>>\n>>> but if the last commit is an empty commit, generated by\n>>>\n>>> $ git commit --allow-empty \"Some commit message\"\n>>>\n>>> then the output of the format patch will be an empty patch. If the\n>>> first case produces something like this:\n>>\n>> I'm not sure if this is a bug or not.\n>>\n>> In the beginning, git's revision-traversal machinery generally does not\n>> show commits which have no diff. Over the years, commands like \"git log\"\n>> learned to set the \"always_show_header\" option to show even empty\n>> commits. But format-patch never did.\n>\n> The patch based workflow support is geared towards helping the\n> recipient of the patches a lot more than the contributors, and to\n> prevent mistakes while applying the patches, \"am\" would stop when it\n> sees such an empty e-mail as you saw (in the later part of message I\n> am not quoting).  After all, a \"format-patch\" output that does not\n> have any patch would be indistinguishable from discussion e-mail\n> messages and the recipient would not want to end up with no-op\n> commits that record such messages.\n>\n> So I think skipping no-op commit from the output was done pretty\n> much deliberately and it is definitely not a bug.  I however do not\n> think it is incorrect to say that it is a lack of feature that\n> nobody so far found necessary or beneficial.\n>\n> I would not refuse to consider adding a new option to \"format-patch\"\n> to emit such a no-op message, and add a \"having no patch is OK, just\n> record a no-op commit\" option to \"am\", though.  But I do not see a\n> clear benefit from such change--it sounds more like a set of\n> \"because we could\" not \"because we need to\" changes to me.\n>\n> Thanks.\n>\n\n\n\n-- \nObrigado,\n\nPedro Rijo\n"}]}