stash: allow pathspecs in the no verb form

Now that stash_push is used in the no verb form of stash, allow specifying the command line for this form as well. Always use -- to disambiguate pathspecs from other non-option arguments. Also make git stash -p an alias for git stash push -p. This allows users to use git stash -p <pathspec>. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed Feb 28, 2017 at 20:33 UTC 9e140909f611fff720efc914b7186b8e4ab722cd
3 files changed +25 -4
Documentation/git-stash.txt
+7 -4
@@ -54,10 +54,13 @@ push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q
54 Save your local modifications to a new 'stash' and roll them
55 back to HEAD (in the working tree and in the index).
56 The <message> part is optional and gives
57 - the description along with the stashed state. For quickly making
58 - a snapshot, you can omit _both_ "save" and <message>, but giving
59 - only <message> does not trigger this action to prevent a misspelled
60 - subcommand from making an unwanted stash.
57 + the description along with the stashed state.
58 ++
59 +For quickly making a snapshot, you can omit "push". In this mode,
60 +non-option arguments are not allowed to prevent a misspelled
61 +subcommand from making an unwanted stash. The two exceptions to this
62 +are `stash -p` which acts as alias for `stash push -p` and pathspecs,
63 +which are allowed after a double hyphen `--` for disambiguation.
64 +
65 When pathspec is given to 'git stash push', the new stash records the
66 modified states only for the files that match the pathspec. The index
git-stash.sh
+3
@@ -656,12 +656,15 @@ apply_to_branch () {
656 }
657 }
658
659 +test "$1" = "-p" && set "push" "$@"
660 +
661 PARSE_CACHE='--not-parsed'
662 # The default command is "push" if nothing but options are given
663 seen_non_option=
664 for opt
665 do
666 case "$opt" in
667 + --) break ;;
668 -*) ;;
669 *) seen_non_option=t; break ;;
670 esac
t/t3903-stash.sh
+15
@@ -892,4 +892,19 @@ test_expect_success 'untracked files are left in place when -u is not given' '
892 test_path_is_file untracked
893 '
894
895 +test_expect_success 'stash without verb with pathspec' '
896 + >"foo bar" &&
897 + >foo &&
898 + >bar &&
899 + git add foo* &&
900 + git stash -- "foo b*" &&
901 + test_path_is_missing "foo bar" &&
902 + test_path_is_file foo &&
903 + test_path_is_file bar &&
904 + git stash pop &&
905 + test_path_is_file "foo bar" &&
906 + test_path_is_file foo &&
907 + test_path_is_file bar
908 +'
909 +
910 test_done