DORMANTno replies

[PATCH] stash: tighten IS_STASH_LIKE logic

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:56:53
Subsystem: the rest · Maintainer: Linus Torvalds

Currently, 'git stash show' and 'git stash apply' can show/apply any
merge commit, as the test for setting IS_STASH_LIKE simply asserts if
the commit is a merge.  Improve the situation by asserting if the
index_commit and the worktree_commit are based off the same commit, by
checking that $REV^1 is equal to $REV^2^1.

Signed-off-by: Ramkumar Ramachandra <redacted>
---
 git-stash.sh     |  3 ++-
 t/t3903-stash.sh | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/git-stash.sh b/git-stash.sh
index bbefdf6..d0428a8 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -366,13 +366,14 @@ parse_flags_and_rev()
 	}
 
 	i_commit=$(git rev-parse --quiet --verify $REV^2 2>/dev/null) &&
-	set -- $(git rev-parse $REV $REV^1 $REV: $REV^1: $REV^2: 2>/dev/null) &&
+	set -- $(git rev-parse $REV $REV^1 $REV: $REV^1: $REV^2: $REV^2^1 2>/dev/null) &&
 	s=$1 &&
 	w_commit=$1 &&
 	b_commit=$2 &&
 	w_tree=$3 &&
 	b_tree=$4 &&
 	i_tree=$5 &&
+	test $b_commit = $6 &&
 	IS_STASH_LIKE=t &&
 	test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
 	IS_STASH_REF=t
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 5dfbda7..11bcd72 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -637,4 +637,15 @@ test_expect_success 'stash where working directory contains "HEAD" file' '
 	test_cmp output expect
 '
 
+test_expect_success 'show refuses to show any random merge commit' '
+	git stash clear &&
+	git reset --hard &&
+	git checkout -b quux &&
+	test_commit bar &&
+	git checkout - &&
+	test_commit foo &&
+	git merge quux &&
+	test_must_fail git stash show HEAD
+'
+
 test_done
-- 
1.8.2.1.423.g4fb5c0a.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help