stash: introduce push verb
Introduce a new git stash push verb in addition to git stash save. The push verb is used to transition from the current command line arguments to a more conventional way, in which the message is given as an argument to the -m option. This allows us to have pathspecs at the end of the command line arguments like other Git commands do, so that the user can say which subset of paths to stash (and leave others behind). Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Gummerer committed
Feb 19, 2017 at 11:03 UTC
f5727e26e44dbbf564034d3993d4d2f65dacd6fb
3 files changed
+55
-3
Documentation/git-stash.txt
+3
@@ -15,6 +15,8 @@ SYNOPSIS
15
'git stash' branch <branchname> [<stash>]
16
'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
17
[-u|--include-untracked] [-a|--all] [<message>]]
18
+'git stash' push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
19
+ [-u|--include-untracked] [-a|--all] [-m|--message <message>]]
20
'git stash' clear
21
'git stash' create [<message>]
22
'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
@@ -46,6 +48,7 @@ OPTIONS
48
-------
49
50
save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
51
+push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>]::
52
53
Save your local modifications to a new 'stash' and roll them
54
back to HEAD (in the working tree and in the index).
git-stash.sh
+43
-3
@@ -9,6 +9,8 @@ USAGE="list [<options>]
9
or: $dashless branch <branchname> [<stash>]
10
or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
11
[-u|--include-untracked] [-a|--all] [<message>]]
12
+ or: $dashless push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
13
+ [-u|--include-untracked] [-a|--all] [-m <message>]
14
or: $dashless clear"
15
16
SUBDIRECTORY_OK=Yes
@@ -189,10 +191,11 @@ store_stash () {
191
return $ret
192
}
193
192
-save_stash () {
194
+push_stash () {
195
keep_index=
196
patch_mode=
197
untracked=
198
+ stash_msg=
199
while test $# != 0
200
do
201
case "$1" in
@@ -216,6 +219,11 @@ save_stash () {
219
-a|--all)
220
untracked=all
221
;;
222
+ -m|--message)
223
+ shift
224
+ test -z ${1+x} && usage
225
+ stash_msg=$1
226
+ ;;
227
--help)
228
show_help
229
;;
@@ -251,8 +259,6 @@ save_stash () {
259
die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")"
260
fi
261
254
- stash_msg="$*"
255
-
262
git update-index -q --refresh
263
if no_changes
264
then
@@ -291,6 +297,36 @@ save_stash () {
297
fi
298
}
299
300
+save_stash () {
301
+ push_options=
302
+ while test $# != 0
303
+ do
304
+ case "$1" in
305
+ --)
306
+ shift
307
+ break
308
+ ;;
309
+ -*)
310
+ # pass all options through to push_stash
311
+ push_options="$push_options $1"
312
+ ;;
313
+ *)
314
+ break
315
+ ;;
316
+ esac
317
+ shift
318
+ done
319
+
320
+ stash_msg="$*"
321
+
322
+ if test -z "$stash_msg"
323
+ then
324
+ push_stash $push_options
325
+ else
326
+ push_stash $push_options -m "$stash_msg"
327
+ fi
328
+}
329
+
330
have_stash () {
331
git rev-parse --verify --quiet $ref_stash >/dev/null
332
}
@@ -617,6 +653,10 @@ save)
653
shift
654
save_stash "$@"
655
;;
656
+push)
657
+ shift
658
+ push_stash "$@"
659
+ ;;
660
apply)
661
shift
662
apply_stash "$@"
t/t3903-stash.sh
+9
@@ -775,4 +775,13 @@ test_expect_success 'stash is not confused by partial renames' '
775
test_path_is_missing file
776
'
777
778
+test_expect_success 'push -m shows right message' '
779
+ >foo &&
780
+ git add foo &&
781
+ git stash push -m "test message" &&
782
+ echo "stash@{0}: On master: test message" >expect &&
783
+ git stash list -1 >actual &&
784
+ test_cmp expect actual
785
+'
786
+
787
test_done