Skip to content

Commit

Permalink
Merge branch 'jc/fail-stash-to-store-non-stash'
Browse files Browse the repository at this point in the history
Feeding "git stash store" with a random commit that was not created
by "git stash create" now errors out.

* jc/fail-stash-to-store-non-stash:
  stash: be careful what we store
  • Loading branch information
gitster committed Oct 23, 2023
2 parents 755fb09 + d9b6634 commit 626f689
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,12 @@ static int show_stash(int argc, const char **argv, const char *prefix)
static int do_store_stash(const struct object_id *w_commit, const char *stash_msg,
int quiet)
{
struct stash_info info;
char revision[GIT_MAX_HEXSZ];

oid_to_hex_r(revision, w_commit);
assert_stash_like(&info, revision);

if (!stash_msg)
stash_msg = "Created via \"git stash store\".";

Expand Down
4 changes: 4 additions & 0 deletions t/t3903-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ test_expect_success 'store called with invalid commit' '
test_must_fail git stash store foo
'

test_expect_success 'store called with non-stash commit' '
test_must_fail git stash store HEAD
'

test_expect_success 'store updates stash ref and reflog' '
git stash clear &&
git reset --hard &&
Expand Down

0 comments on commit 626f689

Please sign in to comment.