Skip to content

Commit 9e14090

Browse files
tgummerergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ada502 commit 9e14090

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Documentation/git-stash.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q
5454
Save your local modifications to a new 'stash' and roll them
5555
back to HEAD (in the working tree and in the index).
5656
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.
6164
+
6265
When pathspec is given to 'git stash push', the new stash records the
6366
modified states only for the files that match the pathspec. The index

git-stash.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,15 @@ apply_to_branch () {
656656
}
657657
}
658658

659+
test "$1" = "-p" && set "push" "$@"
660+
659661
PARSE_CACHE='--not-parsed'
660662
# The default command is "push" if nothing but options are given
661663
seen_non_option=
662664
for opt
663665
do
664666
case "$opt" in
667+
--) break ;;
665668
-*) ;;
666669
*) seen_non_option=t; break ;;
667670
esac

t/t3903-stash.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,19 @@ test_expect_success 'untracked files are left in place when -u is not given' '
892892
test_path_is_file untracked
893893
'
894894

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+
895910
test_done

0 commit comments

Comments
 (0)