Skip to content

Commit c1ba6d9

Browse files
committed
Merge branch 'pw/stash-p-pathspec-fixes' into seen
"git stash -p <pathspec>" improvements. Comments? * pw/stash-p-pathspec-fixes: stash: allow "git stash [<options>] --patch <pathspec>" to assume push stash: allow "git stash -p <pathspec>" to assume push again
2 parents f6cc166 + 42811f8 commit c1ba6d9

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

builtin/stash.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,11 +1858,15 @@ static int push_stash(int argc, const char **argv, const char *prefix,
18581858
int ret;
18591859

18601860
if (argc) {
1861-
force_assume = !strcmp(argv[0], "-p");
1861+
int flags = PARSE_OPT_KEEP_DASHDASH;
1862+
1863+
if (push_assumed)
1864+
flags |= PARSE_OPT_STOP_AT_NON_OPTION;
1865+
18621866
argc = parse_options(argc, argv, prefix, options,
18631867
push_assumed ? git_stash_usage :
1864-
git_stash_push_usage,
1865-
PARSE_OPT_KEEP_DASHDASH);
1868+
git_stash_push_usage, flags);
1869+
force_assume |= patch_mode;
18661870
}
18671871

18681872
if (argc) {

t/t3903-stash.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,25 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
11841184
test_path_is_file bar
11851185
'
11861186

1187+
test_expect_success 'stash --patch <pathspec> stash and restores the file' '
1188+
cat file >expect-file &&
1189+
echo changed-file >file &&
1190+
echo changed-other-file >other-file &&
1191+
echo a | git stash -m "stash bar" --patch file &&
1192+
test_cmp expect-file file &&
1193+
echo changed-other-file >expect &&
1194+
test_cmp expect other-file &&
1195+
git stash pop &&
1196+
test_cmp expect other-file &&
1197+
echo changed-file >expect &&
1198+
test_cmp expect file
1199+
'
1200+
1201+
test_expect_success 'stash <pathspec> -p is rejected' '
1202+
test_must_fail git stash file -p 2>err &&
1203+
test_grep "subcommand wasn${SQ}t specified; ${SQ}push${SQ} can${SQ}t be assumed due to unexpected token ${SQ}file${SQ}" err
1204+
'
1205+
11871206
test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
11881207
mkdir sub &&
11891208
>foo &&

0 commit comments

Comments
 (0)