git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Brandon Casey <drafnel@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] stash: tighten IS_STASH_LIKE logic
Date: Thu, 18 Apr 2013 13:08:37 +0530	[thread overview]
Message-ID: <1366270717-19929-1-git-send-email-artagnon@gmail.com> (raw)

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 <artagnon@gmail.com>
---
 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

             reply	other threads:[~2013-04-18  7:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-18  7:38 Ramkumar Ramachandra [this message]
2013-04-18 22:20 ` [PATCH] stash: tighten IS_STASH_LIKE logic Junio C Hamano
2013-04-19  5:57   ` Ramkumar Ramachandra
2013-04-19 17:50     ` Junio C Hamano
2013-04-19 18:22       ` Ramkumar Ramachandra
2013-04-19 18:54         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1366270717-19929-1-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=drafnel@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).