stash: introduce push verb
authorThomas Gummerer <t.gummerer@gmail.com>
Sun, 19 Feb 2017 11:03:08 +0000 (11:03 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Feb 2017 07:47:41 +0000 (23:47 -0800)
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>
Documentation/git-stash.txt
git-stash.sh
t/t3903-stash.sh
index 2e9e344cd757674a655579c6c58569ff19a6f22e..d240df4af738164dd45114b3a3e3917fef6527e6 100644 (file)
@@ -15,6 +15,8 @@ SYNOPSIS
 'git stash' branch <branchname> [<stash>]
 'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
             [-u|--include-untracked] [-a|--all] [<message>]]
+'git stash' push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
+            [-u|--include-untracked] [-a|--all] [-m|--message <message>]]
 'git stash' clear
 'git stash' create [<message>]
 'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
@@ -46,6 +48,7 @@ OPTIONS
 -------
 
 save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
+push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>]::
 
        Save your local modifications to a new 'stash' and roll them
        back to HEAD (in the working tree and in the index).
index 10c284d1aa2273a3dfe5cc39f1d6738830d02462..8365ebba2ada6865ff01165f62720d6a0809fca4 100755 (executable)
@@ -9,6 +9,8 @@ USAGE="list [<options>]
    or: $dashless branch <branchname> [<stash>]
    or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
                       [-u|--include-untracked] [-a|--all] [<message>]]
+   or: $dashless push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
+                     [-u|--include-untracked] [-a|--all] [-m <message>]
    or: $dashless clear"
 
 SUBDIRECTORY_OK=Yes
@@ -189,10 +191,11 @@ store_stash () {
        return $ret
 }
 
-save_stash () {
+push_stash () {
        keep_index=
        patch_mode=
        untracked=
+       stash_msg=
        while test $# != 0
        do
                case "$1" in
@@ -216,6 +219,11 @@ save_stash () {
                -a|--all)
                        untracked=all
                        ;;
+               -m|--message)
+                       shift
+                       test -z ${1+x} && usage
+                       stash_msg=$1
+                       ;;
                --help)
                        show_help
                        ;;
@@ -251,8 +259,6 @@ save_stash () {
                die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")"
        fi
 
-       stash_msg="$*"
-
        git update-index -q --refresh
        if no_changes
        then
@@ -291,6 +297,36 @@ save_stash () {
        fi
 }
 
+save_stash () {
+       push_options=
+       while test $# != 0
+       do
+               case "$1" in
+               --)
+                       shift
+                       break
+                       ;;
+               -*)
+                       # pass all options through to push_stash
+                       push_options="$push_options $1"
+                       ;;
+               *)
+                       break
+                       ;;
+               esac
+               shift
+       done
+
+       stash_msg="$*"
+
+       if test -z "$stash_msg"
+       then
+               push_stash $push_options
+       else
+               push_stash $push_options -m "$stash_msg"
+       fi
+}
+
 have_stash () {
        git rev-parse --verify --quiet $ref_stash >/dev/null
 }
@@ -617,6 +653,10 @@ save)
        shift
        save_stash "$@"
        ;;
+push)
+       shift
+       push_stash "$@"
+       ;;
 apply)
        shift
        apply_stash "$@"
index 2de3e18ce68a94111c8dfcca858b8515ea8919c1..35771158077f407778ad20edf9c0539defc235f2 100755 (executable)
@@ -775,4 +775,13 @@ test_expect_success 'stash is not confused by partial renames' '
        test_path_is_missing file
 '
 
+test_expect_success 'push -m shows right message' '
+       >foo &&
+       git add foo &&
+       git stash push -m "test message" &&
+       echo "stash@{0}: On master: test message" >expect &&
+       git stash list -1 >actual &&
+       test_cmp expect actual
+'
+
 test_done