OSDN Git Service

stash: refactor stash_create
authorThomas Gummerer <t.gummerer@gmail.com>
Sun, 19 Feb 2017 11:03:10 +0000 (11:03 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Feb 2017 07:47:41 +0000 (23:47 -0800)
Refactor the internal stash_create function to use a -m flag for
specifying the message and -u flag to indicate whether untracked files
should be added to the stash.

This makes it easier to pass a pathspec argument to stash_create in the
next patch.

The user interface for git stash create stays the same.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-stash.sh

index 8365ebb..ef5d1b4 100755 (executable)
@@ -58,8 +58,22 @@ clear_stash () {
 }
 
 create_stash () {
-       stash_msg="$1"
-       untracked="$2"
+       stash_msg=
+       untracked=
+       while test $# != 0
+       do
+               case "$1" in
+               -m|--message)
+                       shift
+                       stash_msg=${1?"BUG: create_stash () -m requires an argument"}
+                       ;;
+               -u|--include-untracked)
+                       shift
+                       untracked=${1?"BUG: create_stash () -u requires an argument"}
+                       ;;
+               esac
+               shift
+       done
 
        git update-index -q --refresh
        if no_changes
@@ -268,7 +282,7 @@ push_stash () {
        git reflog exists $ref_stash ||
                clear_stash || die "$(gettext "Cannot initialize stash")"
 
-       create_stash "$stash_msg" $untracked
+       create_stash -m "$stash_msg" -u "$untracked"
        store_stash -m "$stash_msg" -q $w_commit ||
        die "$(gettext "Cannot save the current status")"
        say "$(eval_gettext "Saved working directory and index state \$stash_msg")"
@@ -667,7 +681,7 @@ clear)
        ;;
 create)
        shift
-       create_stash "$*" && echo "$w_commit"
+       create_stash -m "$*" && echo "$w_commit"
        ;;
 store)
        shift