Skip to content

Commit d9b6634

Browse files
committed
stash: be careful what we store
"git stash store" is meant to store what "git stash create" produces, as these two are implementation details of the end-user facing "git stash save" command. Even though it is clearly documented as such, users would try silly things like "git stash store HEAD" to render their stash unusable. Worse yet, because "git stash drop" does not allow such a stash entry to be removed, "git stash clear" would be the only way to recover from such a mishap. Reuse the logic that allows "drop" to refrain from working on such a stash entry to teach "store" to avoid storing an object that is not a stash entry in the first place. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1bd1d commit d9b6634

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

builtin/stash.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,12 @@ static int show_stash(int argc, const char **argv, const char *prefix)
977977
static int do_store_stash(const struct object_id *w_commit, const char *stash_msg,
978978
int quiet)
979979
{
980+
struct stash_info info;
981+
char revision[GIT_MAX_HEXSZ];
982+
983+
oid_to_hex_r(revision, w_commit);
984+
assert_stash_like(&info, revision);
985+
980986
if (!stash_msg)
981987
stash_msg = "Created via \"git stash store\".";
982988

t/t3903-stash.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,10 @@ test_expect_success 'store called with invalid commit' '
931931
test_must_fail git stash store foo
932932
'
933933

934+
test_expect_success 'store called with non-stash commit' '
935+
test_must_fail git stash store HEAD
936+
'
937+
934938
test_expect_success 'store updates stash ref and reflog' '
935939
git stash clear &&
936940
git reset --hard &&

0 commit comments

Comments
 (0)