aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--builtin/stash.c2
-rwxr-xr-xt/t3903-stash.sh22
2 files changed, 23 insertions, 1 deletions
diff --git a/builtin/stash.c b/builtin/stash.c
index cfbd92852a..bc2c34fa04 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1789,7 +1789,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
int ret;
if (argc) {
- force_assume = !strcmp(argv[0], "-p");
+ force_assume = argc > 1 && !strcmp(argv[1], "-p");
argc = parse_options(argc, argv, prefix, options,
push_assumed ? git_stash_usage :
git_stash_push_usage,
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 74666ff3e4..a99a746221 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1177,6 +1177,28 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
test_path_is_file bar
'
+test_expect_success 'stash -p <pathspec> stash and restores the file' '
+ test_write_lines b c >file &&
+ git commit -m "add a few lines" file &&
+ test_write_lines a b c d >file &&
+ test_write_lines b c d >expect-file &&
+ echo changed-other-file >other-file &&
+ test_write_lines s y n | git stash -p file &&
+ test_cmp expect-file file &&
+ echo changed-other-file >expect &&
+ test_cmp expect other-file &&
+ git checkout HEAD -- file &&
+ git stash pop &&
+ test_cmp expect other-file &&
+ test_write_lines a b c >expect &&
+ test_cmp expect file
+'
+
+test_expect_success 'stash <pathspec> -p is rejected' '
+ test_must_fail git stash file -p 2>err &&
+ test_grep "subcommand wasn${SQ}t specified; ${SQ}push${SQ} can${SQ}t be assumed due to unexpected token ${SQ}file${SQ}" err
+'
+
test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
mkdir sub &&
>foo &&