Skip to content

Commit 9ca6326

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

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

git-stash.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,22 @@ clear_stash () {
5858
}
5959

6060
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
6377

6478
git update-index -q --refresh
6579
if no_changes
@@ -268,7 +282,7 @@ push_stash () {
268282
git reflog exists $ref_stash ||
269283
clear_stash || die "$(gettext "Cannot initialize stash")"
270284

271-
create_stash "$stash_msg" $untracked
285+
create_stash -m "$stash_msg" -u "$untracked"
272286
store_stash -m "$stash_msg" -q $w_commit ||
273287
die "$(gettext "Cannot save the current status")"
274288
say "$(eval_gettext "Saved working directory and index state \$stash_msg")"
@@ -667,7 +681,7 @@ clear)
667681
;;
668682
create)
669683
shift
670-
create_stash "$*" && echo "$w_commit"
684+
create_stash -m "$*" && echo "$w_commit"
671685
;;
672686
store)
673687
shift

0 commit comments

Comments
 (0)