stash: refactor stash_create
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>
Thomas Gummerer committed
Feb 19, 2017 at 11:03 UTC
9ca6326dff29b97cfb126e6460105920c492fa15
1 file changed
+18
-4
git-stash.sh
+18
-4
@@ -58,8 +58,22 @@ clear_stash () {
58
}
59
60
create_stash () {
61
- stash_msg="$1"
62
- untracked="$2"
61
+ stash_msg=
62
+ untracked=
63
+ while test $# != 0
64
+ do
65
+ case "$1" in
66
+ -m|--message)
67
+ shift
68
+ stash_msg=${1?"BUG: create_stash () -m requires an argument"}
69
+ ;;
70
+ -u|--include-untracked)
71
+ shift
72
+ untracked=${1?"BUG: create_stash () -u requires an argument"}
73
+ ;;
74
+ esac
75
+ shift
76
+ done
77
78
git update-index -q --refresh
79
if no_changes
@@ -268,7 +282,7 @@ push_stash () {
282
git reflog exists $ref_stash ||
283
clear_stash || die "$(gettext "Cannot initialize stash")"
284
271
- create_stash "$stash_msg" $untracked
285
+ create_stash -m "$stash_msg" -u "$untracked"
286
store_stash -m "$stash_msg" -q $w_commit ||
287
die "$(gettext "Cannot save the current status")"
288
say "$(eval_gettext "Saved working directory and index state \$stash_msg")"
@@ -667,7 +681,7 @@ clear)
681
;;
682
create)
683
shift
670
- create_stash "$*" && echo "$w_commit"
684
+ create_stash -m "$*" && echo "$w_commit"
685
;;
686
store)
687
shift