{"thread":{"id":"32467","subject":"\"fatal: git-write-tree: error building trees\" from `git stash`","startedAt":"2012-12-27T18:07:06Z","lastAt":"2012-12-27T20:11:37Z","messageCount":6,"participants":["Alex Vandiver","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"205558","messageId":"1356631626.13818.126.camel@umgah.localdomain","threadId":"32467","inReplyTo":null,"subject":"\"fatal: git-write-tree: error building trees\" from `git stash`","fromName":"Alex Vandiver","fromEmail":"alex@chmrr.net","sentAt":"2012-12-27T18:07:06Z","receivedAt":"2012-12-27T18:07:06Z","isPatch":false,"sender":{"key":"alex@chmrr.net","avatar":"https://avatars.githubusercontent.com/u/28347?v=4"},"body":"  Heya,\nI just ran into the following with `git stash`.  The set-up:\n\n        git init\n        echo \"Initial\" > foo\n        git add .\n        git commit -m 'Initial commit'\n        echo \"Rewrite\" > foo\n        git commit -am 'Second commit, rewrites content'\n        echo \"Stashed changes\" >> foo\n        git stash\n        git co HEAD~\n        \n$ git stash pop\nAuto-merging foo\nCONFLICT (content): Merge conflict in foo\nRecorded preimage for 'foo'\n\n$ git stash\nfoo: needs merge\nfoo: needs merge\nfoo: unmerged (aeaa7e5e87cf309a7368d5d92a71c1f9e6a8c9e7)\nfoo: unmerged (a77fa514de2720c72c1a861de098595959a2c97a)\nfoo: unmerged (4a622d2b991f1a19ba7be313a46dc6f03692cd0a)\nfatal: git-write-tree: error building trees\nCannot save the current index state\n\n - Alex\n"},{"id":"205561","messageId":"7vsj6rl456.fsf@alter.siamese.dyndns.org","threadId":"32467","inReplyTo":"1356631626.13818.126.camel@umgah.localdomain","subject":"Re: \"fatal: git-write-tree: error building trees\" from `git stash`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-27T18:51:49Z","receivedAt":"2012-12-27T18:51:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Vandiver <alex@chmrr.net> writes:\n\n> Heya,\n> I just ran into the following with `git stash`.  The set-up:\n> ...\n> $ git stash pop\n> Auto-merging foo\n> CONFLICT (content): Merge conflict in foo\n> Recorded preimage for 'foo'\n>\n> $ git stash\n> foo: needs merge\n> foo: needs merge\n> foo: unmerged (aeaa7e5e87cf309a7368d5d92a71c1f9e6a8c9e7)\n> foo: unmerged (a77fa514de2720c72c1a861de098595959a2c97a)\n> foo: unmerged (4a622d2b991f1a19ba7be313a46dc6f03692cd0a)\n> fatal: git-write-tree: error building trees\n> Cannot save the current index state\n\nThis is totally expected, isn't it?\n\nYou do not save state in the middle of a conflict with \"git stash\"\n(instead, you would \"git stash\" away your own work in progress\nbefore you start operation that may create and leave conflicts).\n"},{"id":"205562","messageId":"1356634556.13818.136.camel@umgah.localdomain","threadId":"32467","inReplyTo":"7vsj6rl456.fsf@alter.siamese.dyndns.org","subject":"Re: \"fatal: git-write-tree: error building trees\" from `git stash`","fromName":"Alex Vandiver","fromEmail":"alex@chmrr.net","sentAt":"2012-12-27T18:55:56Z","receivedAt":"2012-12-27T18:55:56Z","isPatch":false,"sender":{"key":"alex@chmrr.net","avatar":"https://avatars.githubusercontent.com/u/28347?v=4"},"body":"On Thu, 2012-12-27 at 10:51 -0800, Junio C Hamano wrote:\n> > $ git stash\n> > foo: needs merge\n> > foo: needs merge\n> > foo: unmerged (aeaa7e5e87cf309a7368d5d92a71c1f9e6a8c9e7)\n> > foo: unmerged (a77fa514de2720c72c1a861de098595959a2c97a)\n> > foo: unmerged (4a622d2b991f1a19ba7be313a46dc6f03692cd0a)\n> > fatal: git-write-tree: error building trees\n> > Cannot save the current index state\n> \n> This is totally expected, isn't it?\n> \n> You do not save state in the middle of a conflict with \"git stash\"\n> (instead, you would \"git stash\" away your own work in progress\n> before you start operation that may create and leave conflicts).\n\nApologies for not being clear.  While being unable to stash is not\nunexpected, perhaps, \"Cannot stash while resolving conflicts\" or similar\nwould be more understandable to the end user than the above.\n - Alex\n"},{"id":"205563","messageId":"20121227190542.GB28811@sigill.intra.peff.net","threadId":"32467","inReplyTo":"1356634556.13818.136.camel@umgah.localdomain","subject":"Re: \"fatal: git-write-tree: error building trees\" from `git stash`","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-12-27T19:05:42Z","receivedAt":"2012-12-27T19:05:42Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Dec 27, 2012 at 01:55:56PM -0500, Alex Vandiver wrote:\n\n> On Thu, 2012-12-27 at 10:51 -0800, Junio C Hamano wrote:\n> > > $ git stash\n> > > foo: needs merge\n> > > foo: needs merge\n> > > foo: unmerged (aeaa7e5e87cf309a7368d5d92a71c1f9e6a8c9e7)\n> > > foo: unmerged (a77fa514de2720c72c1a861de098595959a2c97a)\n> > > foo: unmerged (4a622d2b991f1a19ba7be313a46dc6f03692cd0a)\n> > > fatal: git-write-tree: error building trees\n> > > Cannot save the current index state\n> > \n> > This is totally expected, isn't it?\n> > \n> > You do not save state in the middle of a conflict with \"git stash\"\n> > (instead, you would \"git stash\" away your own work in progress\n> > before you start operation that may create and leave conflicts).\n> \n> Apologies for not being clear.  While being unable to stash is not\n> unexpected, perhaps, \"Cannot stash while resolving conflicts\" or similar\n> would be more understandable to the end user than the above.\n\nYeah, I think the outcome is reasonable, but that message is just\nhorrible. Something like this might be better:\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 688e259..7ea425c 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -217,6 +217,12 @@ save_stash () {\n \n \tstash_msg=\"$*\"\n \n+\tif ! git diff-index --cached --diff-filter=U --quiet HEAD; then\n+\t\techo >&2 \"fatal: unable to stash unmerged entries:\"\n+\t\tgit diff-index --cached --diff-filter=U --name-status HEAD\n+\t\texit 1\n+\tfi\n+\n \tgit update-index -q --refresh\n \tif no_changes\n \tthen\n\nbut I suspect it is not sufficient:\n\n  1. There are other code paths that will end up in write-tree which\n     should probably be protected, too.\n\n  2. Unmerged entries are only one reason that write-tree might fail.\n     It's OK not to catch them all (since ultimately write-tree will\n     complain if need be), but we may want to also handle intent-to-add\n     entries with a nicer message.\n\n-Peff\n"},{"id":"205564","messageId":"7vlicjl2r8.fsf@alter.siamese.dyndns.org","threadId":"32467","inReplyTo":"1356634556.13818.136.camel@umgah.localdomain","subject":"Re: \"fatal: git-write-tree: error building trees\" from `git stash`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-27T19:21:47Z","receivedAt":"2012-12-27T19:21:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Vandiver <alex@chmrr.net> writes:\n\n> ... \"Cannot stash while resolving conflicts\" or similar would be\n> more understandable to the end user than the above.\n\nInterestingly enough, the \"apply\" side is protected with this one\nliner:\n\n        # current index state\n        c_tree=$(git write-tree) ||\n                die \"$(gettext \"Cannot apply a stash in the middle of a merge\")\"\n\nsince 5fd448f (git stash: Give friendlier errors when there is\nnothing to apply, 2009-08-11).  I would think something in line with\nthat change on the \"create\" side is a welcome one.\n\nThanks.\n"},{"id":"205565","messageId":"7vhan7l0g6.fsf@alter.siamese.dyndns.org","threadId":"32467","inReplyTo":"20121227190542.GB28811@sigill.intra.peff.net","subject":"Re: \"fatal: git-write-tree: error building trees\" from `git stash`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-27T20:11:37Z","receivedAt":"2012-12-27T20:11:37Z","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> but I suspect it is not sufficient:\n>\n>   1. There are other code paths that will end up in write-tree which\n>      should probably be protected, too.\n\nAmong 6 calls to write-tree, only the first ones in create_stash and\napply_stash are about the index the user originally had.  If the\nonly expected failure case is unmerged entries, it should be\nsufficient to protect these two (and the one in apply_stash is\nalready covered, I think).\n\n>   2. Unmerged entries are only one reason that write-tree might fail.\n>      It's OK not to catch them all (since ultimately write-tree will\n>      complain if need be), but we may want to also handle intent-to-add\n>      entries with a nicer message.\n\nHrmph.\n\nWe used to fail write-tree when I-T-A entries existed and relied on\nthat behaviour to implement \"no state lost\"; as we broke write-tree\nrecently by allowing to write a tree out by pretending that I-T-A\nentries do not exist, I think we broke it.  Stashing with I-T-A and\nthen unstashing it may lose the file.  Sigh...\n"}]}