]> git.ipfire.org Git - thirdparty/git.git/commitdiff
stash: allow pathspecs in the no verb form
authorThomas Gummerer <t.gummerer@gmail.com>
Tue, 28 Feb 2017 20:33:40 +0000 (20:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Feb 2017 22:21:10 +0000 (14:21 -0800)
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>
Documentation/git-stash.txt
git-stash.sh
t/t3903-stash.sh

index 4d8d30f179967775381c878d6d96ce4f9b334769..70191d06b69ed307c6ce1d8f46c158b61eb6545f 100644 (file)
@@ -54,10 +54,13 @@ push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q
        Save your local modifications to a new 'stash' and roll them
        back to HEAD (in the working tree and in the index).
        The <message> part is optional and gives
-       the description along with the stashed state.  For quickly making
-       a snapshot, you can omit _both_ "save" and <message>, but giving
-       only <message> does not trigger this action to prevent a misspelled
-       subcommand from making an unwanted stash.
+       the description along with the stashed state.
++
+For quickly making a snapshot, you can omit "push".  In this mode,
+non-option arguments are not allowed to prevent a misspelled
+subcommand from making an unwanted stash.  The two exceptions to this
+are `stash -p` which acts as alias for `stash push -p` and pathspecs,
+which are allowed after a double hyphen `--` for disambiguation.
 +
 When pathspec is given to 'git stash push', the new stash records the
 modified states only for the files that match the pathspec.  The index
index 2b74d733b1946b2738546bfcfc60e286f02e59be..9c70662cc81269316375c54cf45a9c838b384a85 100755 (executable)
@@ -656,12 +656,15 @@ apply_to_branch () {
        }
 }
 
+test "$1" = "-p" && set "push" "$@"
+
 PARSE_CACHE='--not-parsed'
 # The default command is "push" if nothing but options are given
 seen_non_option=
 for opt
 do
        case "$opt" in
+       --) break ;;
        -*) ;;
        *) seen_non_option=t; break ;;
        esac
index e875fe8259218387a1fafd8030570ac0b33a2477..89877e4b52a4aa09b1e1925005a1a09826e2c7a0 100755 (executable)
@@ -892,4 +892,19 @@ test_expect_success 'untracked files are left in place when -u is not given' '
        test_path_is_file untracked
 '
 
+test_expect_success 'stash without verb with pathspec' '
+       >"foo bar" &&
+       >foo &&
+       >bar &&
+       git add foo* &&
+       git stash -- "foo b*" &&
+       test_path_is_missing "foo bar" &&
+       test_path_is_file foo &&
+       test_path_is_file bar &&
+       git stash pop &&
+       test_path_is_file "foo bar" &&
+       test_path_is_file foo &&
+       test_path_is_file bar
+'
+
 test_done