Skip to contentSkip to conversation

git stash apply segfaulting when called in subdir

DISCUSSION Uwe Kleine-König 5 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hello,

I did not do much testing and didn't look into the issue yet:

zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init
Initialized empty Git repository in .git/
zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file
zeisberg@cassiopeia:/tmp/repo$ git add file dir/file
zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala
Created initial commit 265b7d7: tralala
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 dir/file
 create mode 100644 file
zeisberg@cassiopeia:/tmp/repo$ echo three >> file
zeisberg@cassiopeia:/tmp/repo$ git stash
Saved "WIP on master: 265b7d7... tralala"
HEAD is now at 265b7d7... tralala
zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

Best regards
Uwe

Signature · 3 lines
Uwe Kleine-König

http://www.google.com/search?q=1+newton+in+kg*m+%2F+s%5E2
#1 lore raw
Quoted 3 lines · Uwe Kleine-König
zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

I've been seeing this, as well.

Signature · 8 lines
-Steven Walter <[email protected]>
"A human being should be able to change a diaper, plan an invasion,
butcher a hog, conn a ship, design a building, write a sonnet, balance
accounts, build a wall, set a bone, comfort the dying, take orders,
give orders, cooperate, act alone, solve equations, analyze a new
problem, pitch manure, program a computer, cook a tasty meal, fight
efficiently, die gallantly. Specialization is for insects."
   -Robert Heinlein
#2 lore raw
In reply to Uwe Kleine-König
Quoted 15 lines · Uwe Kleine-König
zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init
Initialized empty Git repository in .git/
zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file
zeisberg@cassiopeia:/tmp/repo$ git add file dir/file
zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala
Created initial commit 265b7d7: tralala
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 dir/file
 create mode 100644 file
zeisberg@cassiopeia:/tmp/repo$ echo three >> file
Quoted 7 lines
zeisberg@cassiopeia:/tmp/repo$ git stash
Saved "WIP on master: 265b7d7... tralala"
HEAD is now at 265b7d7... tralala
zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

This probably is a merge-recursive bug, but in the meantime, I think this should fix it.

---

 git-stash.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
git-stash.sh +1 -0
index de13dd1..d9cd42d 100755
@@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 require_work_tree
+cd_to_toplevel
 
 TMP="$GIT_DIR/.git-stash.$$"
 trap 'rm -f "$TMP-*"' 0
#3 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 3 lines
zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

This probably is a merge-recursive bug, but in the meantime, I think this should fix it.

The merge-recursive bug is simply a failure to check for invalid input. Patch to at least print and die rather than segfault is below. Technically the error could be from a tag dereference, too, so maybe the error message should be more exact?

-- >8 --
merge-recursive: don't segfault on missing input objects

This should generally never happen, but it's nicer to report an error than to segfault.

---
 merge-recursive.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
merge-recursive.c +2 -0
index c8539ec..2764e61 100644
@@ -1692,6 +1692,8 @@ static struct commit *get_ref(const char *ref)
 	if (get_sha1(ref, sha1))
 		die("Could not resolve ref '%s'", ref);
 	object = deref_tag(parse_object(sha1), ref, strlen(ref));
+	if (!object)
+		die("Object does not exist: %s", ref);
 	if (object->type == OBJ_TREE)
 		return make_virtual_commit((struct tree*)object,
 			better_branch_name(ref));
Signature · 1 line
1.5.3.rc3.818.gc1dc7-dirty
#4 lore raw

Hi,

Quoted 10 lines · Jeff King
Quoted 6 lines · Junio C Hamano
Quoted 3 lines
zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

This probably is a merge-recursive bug, but in the meantime, I think this should fix it.

The merge-recursive bug is simply a failure to check for invalid input.

No it is not.

The objects are there. But the objects cannot be found, since merge-recursive cannot go to top level.

Ciao,
Dscho

#5 lore raw
Quoted 6 lines · Johannes Schindelin
Quoted 1 line

The merge-recursive bug is simply a failure to check for invalid input.

No it is not.

The objects are there. But the objects cannot be found, since merge-recursive cannot go to top level.

Fair enough, I should have looked a little further. However, I still wonder if it's better to report an error than to segfault.

-Peff

#6 lore raw
In reply to Junio C Hamano

Hi,

Quoted 38 lines · Junio C Hamano
Quoted 15 lines · Uwe Kleine-König
zeisberg@cassiopeia:/tmp$ mkdir repo; cd repo; git init
Initialized empty Git repository in .git/
zeisberg@cassiopeia:/tmp/repo$ mkdir dir; echo one > file; echo two > dir/file
zeisberg@cassiopeia:/tmp/repo$ git add file dir/file
zeisberg@cassiopeia:/tmp/repo$ git commit -m tralala
Created initial commit 265b7d7: tralala
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 dir/file
 create mode 100644 file
zeisberg@cassiopeia:/tmp/repo$ echo three >> file
Quoted 7 lines
zeisberg@cassiopeia:/tmp/repo$ git stash
Saved "WIP on master: 265b7d7... tralala"
HEAD is now at 265b7d7... tralala
zeisberg@cassiopeia:/tmp/repo$ cd dir; git stash apply
error: missing object referenced by '696146c2a44d7fc4d5ae4a71589c4c0d84f59789'
/home/zeisberg/usr/bin/git-stash: line 111: 13618 Segmentation fault      git-merge-recursive $b_tree -- $c_tree $w_tree

This probably is a merge-recursive bug, but in the meantime, I think this should fix it.

---

 git-stash.sh |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
git-stash.sh +0 -0
index de13dd1..d9cd42d 100755

git-stash.sh USAGE='[ | list | show | apply | clear]' · line 12

Quoted 7 lines
git-stash.sh +1 -0
@@ -6,6 +6,7 @@ USAGE='[ | list | show | apply | clear]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 require_work_tree
+cd_to_toplevel
 
 TMP="$GIT_DIR/.git-stash.$$"
 trap 'rm -f "$TMP-*"' 0

It does... And here is a test case:

-- snipsnap --
[PATCH] Test "stash apply" in a subdirectory

---

 t/t3903-stash.sh |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
t/t3903-stash.sh +14 -0
index 392ac1c..9e363fd 100755
@@ -66,4 +66,18 @@ test_expect_success 'apply stashed changes (including index)' '
 	test 1 = $(git show HEAD:file)
 '
 
+test_expect_success 'apply in subdir' '
+	git --git-dir=new init &&
+	cd new &&
+	mkdir dir &&
+	echo one > file &&
+	echo two > dir/file &&
+	git add file dir/file &&
+	git commit -m first &&
+	echo three >> file &&
+	git stash &&
+	cd dir &&
+	git stash apply
+'
+
 test_done