diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-06-24 09:48:47 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-06-24 09:48:47 -0700 |
| commit | d2fb10344798a9bfb76592e20715131dfac11a51 (patch) | |
| tree | de70d3baaf1d8ac986975f8b3d4fd78c2a897048 | |
| parent | afe1a7aee768e3171e83772d0587e789ca0de3df (diff) | |
| parent | 468817bab2ab5fd9b71a8df49e02b8d5521b1631 (diff) | |
| download | git-d2fb10344798a9bfb76592e20715131dfac11a51.tar.xz | |
Merge branch 'pw/stash-p-pathspec-fixes'
"git stash -p <pathspec>" improvements.
* 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
| -rw-r--r-- | builtin/stash.c | 10 | ||||
| -rwxr-xr-x | t/t3903-stash.sh | 22 |
2 files changed, 29 insertions, 3 deletions
diff --git a/builtin/stash.c b/builtin/stash.c index cfbd92852a..b12fd6c40f 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1789,11 +1789,15 @@ static int push_stash(int argc, const char **argv, const char *prefix, int ret; if (argc) { - force_assume = !strcmp(argv[0], "-p"); + int flags = PARSE_OPT_KEEP_DASHDASH; + + if (push_assumed) + flags |= PARSE_OPT_STOP_AT_NON_OPTION; + argc = parse_options(argc, argv, prefix, options, push_assumed ? git_stash_usage : - git_stash_push_usage, - PARSE_OPT_KEEP_DASHDASH); + git_stash_push_usage, flags); + force_assume |= patch_mode; } if (argc) { diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 74666ff3e4..2bba3baa10 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 --patch <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 -m "stash bar" --patch 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 && |
