{"thread":{"id":"9224","subject":"git stash apply segfaulting when called in subdir","startedAt":"2007-07-25T21:23:11Z","lastAt":"2007-07-26T05:48:00Z","messageCount":7,"participants":["Uwe Kleine-König","Junio C Hamano","Steven Walter","Johannes Schindelin","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"48594","messageId":"20070725212311.GA13325@cassiopeia","threadId":"9224","inReplyTo":null,"subject":"git stash apply segfaulting when called in subdir","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-07-25T21:23:11Z","receivedAt":"2007-07-25T21:23:11Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello,\n\nI did not do much testing and didn't look into the issue yet:\n\nzeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init\nInitialized empty Git repository in .git/\n\nzeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file\n\nzeisberg@cassiopeia:/tmp/repo$ git add file dir/file\n\nzeisberg@cassiopeia:/tmp/repo$ git commit -m tralala\nCreated initial commit 265b7d7: tralala\n 2 files changed, 2 insertions(+), 0 deletions(-)\n create mode 100644 dir/file\n create mode 100644 file\n\nzeisberg@cassiopeia:/tmp/repo$ echo three >> file\n\nzeisberg@cassiopeia:/tmp/repo$ git stash\nSaved \"WIP on master: 265b7d7... tralala\"\nHEAD is now at 265b7d7... tralala\n\nzeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply\nerror: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'\n/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree\n\nBest regards\nUwe\n\n-- \nUwe Kleine-König\n\nhttp://www.google.com/search?q=1+newton+in+kg*m+%2F+s%5E2\n"},{"id":"48599","messageId":"7v1wewdsoz.fsf@assigned-by-dhcp.cox.net","threadId":"9224","inReplyTo":"20070725212311.GA13325@cassiopeia","subject":"Re: git stash apply segfaulting when called in subdir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-25T22:28:12Z","receivedAt":"2007-07-25T22:28:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:\n\n> zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init\n> Initialized empty Git repository in .git/\n>\n> zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file\n>\n> zeisberg@cassiopeia:/tmp/repo$ git add file dir/file\n>\n> zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala\n> Created initial commit 265b7d7: tralala\n>  2 files changed, 2 insertions(+), 0 deletions(-)\n>  create mode 100644 dir/file\n>  create mode 100644 file\n>\n> zeisberg@cassiopeia:/tmp/repo$ echo three >> file\n>\n> zeisberg@cassiopeia:/tmp/repo$ git stash\n> Saved \"WIP on master: 265b7d7... tralala\"\n> HEAD is now at 265b7d7... tralala\n>\n> zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply\n> error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'\n> /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree\n\nThis probably is a merge-recursive bug, but in the meantime,\nI think this should fix it.\n\n---\n\n git-stash.sh |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex de13dd1..d9cd42d 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]'\n SUBDIRECTORY_OK=Yes\n . git-sh-setup\n require_work_tree\n+cd_to_toplevel\n \n TMP=\"$GIT_DIR/.git-stash.$$\"\n trap 'rm -f \"$TMP-*\"' 0\n"},{"id":"48600","messageId":"20070725223244.GB21274@dervierte","threadId":"9224","inReplyTo":"20070725212311.GA13325@cassiopeia","subject":"Re: git stash apply segfaulting when called in subdir","fromName":"Steven Walter","fromEmail":"stevenrwalter@gmail.com","sentAt":"2007-07-25T22:32:44Z","receivedAt":"2007-07-25T22:32:44Z","isPatch":false,"sender":{"key":"stevenrwalter@gmail.com","avatar":"https://avatars.githubusercontent.com/u/79127?v=4"},"body":"On Wed, Jul 25, 2007 at 11:23:11PM +0200, Uwe Kleine-König wrote:\n> zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply\n> error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'\n> /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree\n\nI've been seeing this, as well.\n-- \n-Steven Walter <stevenrwalter@gmail.com>\n\"A human being should be able to change a diaper, plan an invasion,\nbutcher a hog, conn a ship, design a building, write a sonnet, balance\naccounts, build a wall, set a bone, comfort the dying, take orders,\ngive orders, cooperate, act alone, solve equations, analyze a new\nproblem, pitch manure, program a computer, cook a tasty meal, fight\nefficiently, die gallantly. Specialization is for insects.\"\n   -Robert Heinlein\n"},{"id":"48605","messageId":"Pine.LNX.4.64.0707260001091.14781@racer.site","threadId":"9224","inReplyTo":"7v1wewdsoz.fsf@assigned-by-dhcp.cox.net","subject":"Re: git stash apply segfaulting when called in subdir","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-25T23:01:52Z","receivedAt":"2007-07-25T23:01:52Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 25 Jul 2007, Junio C Hamano wrote:\n\n> Uwe Kleine-König  <ukleinek@informatik.uni-freiburg.de> writes:\n> \n> > zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init\n> > Initialized empty Git repository in .git/\n> >\n> > zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file\n> >\n> > zeisberg@cassiopeia:/tmp/repo$ git add file dir/file\n> >\n> > zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala\n> > Created initial commit 265b7d7: tralala\n> >  2 files changed, 2 insertions(+), 0 deletions(-)\n> >  create mode 100644 dir/file\n> >  create mode 100644 file\n> >\n> > zeisberg@cassiopeia:/tmp/repo$ echo three >> file\n> >\n> > zeisberg@cassiopeia:/tmp/repo$ git stash\n> > Saved \"WIP on master: 265b7d7... tralala\"\n> > HEAD is now at 265b7d7... tralala\n> >\n> > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply\n> > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'\n> > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree\n> \n> This probably is a merge-recursive bug, but in the meantime,\n> I think this should fix it.\n> \n> ---\n> \n>  git-stash.sh |    1 +\n>  1 files changed, 1 insertions(+), 0 deletions(-)\n> \n> diff --git a/git-stash.sh b/git-stash.sh\n> index de13dd1..d9cd42d 100755\n> --- a/git-stash.sh\n> +++ b/git-stash.sh\n> @@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]'\n>  SUBDIRECTORY_OK=Yes\n>  . git-sh-setup\n>  require_work_tree\n> +cd_to_toplevel\n>  \n>  TMP=\"$GIT_DIR/.git-stash.$$\"\n>  trap 'rm -f \"$TMP-*\"' 0\n\nIt does... And here is a test case:\n\n-- snipsnap --\n[PATCH] Test \"stash apply\" in a subdirectory\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n t/t3903-stash.sh |   14 ++++++++++++++\n 1 files changed, 14 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 392ac1c..9e363fd 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -66,4 +66,18 @@ test_expect_success 'apply stashed changes (including index)' '\n \ttest 1 = $(git show HEAD:file)\n '\n \n+test_expect_success 'apply in subdir' '\n+\tgit --git-dir=new init &&\n+\tcd new &&\n+\tmkdir dir &&\n+\techo one > file &&\n+\techo two > dir/file &&\n+\tgit add file dir/file &&\n+\tgit commit -m first &&\n+\techo three >> file &&\n+\tgit stash &&\n+\tcd dir &&\n+\tgit stash apply\n+'\n+\n test_done"},{"id":"48637","messageId":"20070726050726.GC32617@coredump.intra.peff.net","threadId":"9224","inReplyTo":"7v1wewdsoz.fsf@assigned-by-dhcp.cox.net","subject":"Re: git stash apply segfaulting when called in subdir","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-07-26T05:07:26Z","receivedAt":"2007-07-26T05:07:26Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jul 25, 2007 at 03:28:12PM -0700, Junio C Hamano wrote:\n\n> > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply\n> > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'\n> > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree\n> \n> This probably is a merge-recursive bug, but in the meantime,\n> I think this should fix it.\n\nThe merge-recursive bug is simply a failure to check for invalid input.\nPatch to at least print and die rather than segfault is below.\nTechnically the error could be from a tag dereference, too, so maybe the\nerror message should be more exact?\n\n-- >8 --\nmerge-recursive: don't segfault on missing input objects\n\nThis should generally never happen, but it's nicer to report\nan error than to segfault.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n merge-recursive.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex c8539ec..2764e61 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -1692,6 +1692,8 @@ static struct commit *get_ref(const char *ref)\n \tif (get_sha1(ref, sha1))\n \t\tdie(\"Could not resolve ref '%s'\", ref);\n \tobject = deref_tag(parse_object(sha1), ref, strlen(ref));\n+\tif (!object)\n+\t\tdie(\"Object does not exist: %s\", ref);\n \tif (object->type == OBJ_TREE)\n \t\treturn make_virtual_commit((struct tree*)object,\n \t\t\tbetter_branch_name(ref));\n-- \n1.5.3.rc3.818.gc1dc7-dirty\n"},{"id":"48642","messageId":"Pine.LNX.4.64.0707260635060.14781@racer.site","threadId":"9224","inReplyTo":"20070726050726.GC32617@coredump.intra.peff.net","subject":"Re: git stash apply segfaulting when called in subdir","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-26T05:40:44Z","receivedAt":"2007-07-26T05:40:44Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 26 Jul 2007, Jeff King wrote:\n\n> On Wed, Jul 25, 2007 at 03:28:12PM -0700, Junio C Hamano wrote:\n> \n> > > zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply\n> > > error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'\n> > > /home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree\n> > \n> > This probably is a merge-recursive bug, but in the meantime,\n> > I think this should fix it.\n> \n> The merge-recursive bug is simply a failure to check for invalid input.\n\nNo it is not.\n\nThe objects are there.  But the objects cannot be found, since \nmerge-recursive cannot go to top level.\n\nCiao,\nDscho\n"},{"id":"48643","messageId":"20070726054800.GA21518@coredump.intra.peff.net","threadId":"9224","inReplyTo":"Pine.LNX.4.64.0707260635060.14781@racer.site","subject":"Re: git stash apply segfaulting when called in subdir","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-07-26T05:48:00Z","receivedAt":"2007-07-26T05:48:00Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jul 26, 2007 at 06:40:44AM +0100, Johannes Schindelin wrote:\n\n> > The merge-recursive bug is simply a failure to check for invalid input.\n> \n> No it is not.\n> \n> The objects are there.  But the objects cannot be found, since \n> merge-recursive cannot go to top level.\n\nFair enough, I should have looked a little further. However, I still\nwonder if it's better to report an error than to segfault.\n\n-Peff\n"}]}