@@ -7,8 +7,11 @@ USAGE="list [<options>]
7
7
or: $dashless drop [-q|--quiet] [<stash>]
8
8
or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
9
9
or: $dashless branch <branchname> [<stash>]
10
- or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
11
- [-u|--include-untracked] [-a|--all] [<message>]]
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
+ [-- <pathspec>...]]
12
15
or: $dashless clear"
13
16
14
17
SUBDIRECTORY_OK=Yes
33
36
fi
34
37
35
38
no_changes () {
36
- git diff-index --quiet --cached HEAD --ignore-submodules -- &&
37
- git diff-files --quiet --ignore-submodules &&
39
+ git diff-index --quiet --cached HEAD --ignore-submodules -- " $@ " &&
40
+ git diff-files --quiet --ignore-submodules -- " $@ " &&
38
41
(test -z " $untracked " || test -z " $( untracked_files) " )
39
42
}
40
43
41
44
untracked_files () {
42
45
excl_opt=--exclude-standard
43
46
test " $untracked " = " all" && excl_opt=
44
- git ls-files -o -z $excl_opt
47
+ git ls-files -o -z $excl_opt -- " $@ "
45
48
}
46
49
47
50
clear_stash () {
@@ -56,11 +59,29 @@ clear_stash () {
56
59
}
57
60
58
61
create_stash () {
59
- stash_msg=" $1 "
60
- untracked=" $2 "
62
+ stash_msg=
63
+ untracked=
64
+ while test $# ! = 0
65
+ do
66
+ case " $1 " in
67
+ -m|--message)
68
+ shift
69
+ stash_msg=${1?" BUG: create_stash () -m requires an argument" }
70
+ ;;
71
+ -u|--include-untracked)
72
+ shift
73
+ untracked=${1?" BUG: create_stash () -u requires an argument" }
74
+ ;;
75
+ --)
76
+ shift
77
+ break
78
+ ;;
79
+ esac
80
+ shift
81
+ done
61
82
62
83
git update-index -q --refresh
63
- if no_changes
84
+ if no_changes " $@ "
64
85
then
65
86
exit 0
66
87
fi
@@ -92,7 +113,7 @@ create_stash () {
92
113
# Untracked files are stored by themselves in a parentless commit, for
93
114
# ease of unpacking later.
94
115
u_commit=$(
95
- untracked_files | (
116
+ untracked_files " $@ " | (
96
117
GIT_INDEX_FILE=" $TMPindex " &&
97
118
export GIT_INDEX_FILE &&
98
119
rm -f " $TMPindex " &&
@@ -115,7 +136,7 @@ create_stash () {
115
136
git read-tree --index-output=" $TMPindex " -m $i_tree &&
116
137
GIT_INDEX_FILE=" $TMPindex " &&
117
138
export GIT_INDEX_FILE &&
118
- git diff-index --name-only -z HEAD -- > " $TMP -stagenames" &&
139
+ git diff-index --name-only -z HEAD -- " $@ " > " $TMP -stagenames" &&
119
140
git update-index -z --add --remove --stdin < " $TMP -stagenames" &&
120
141
git write-tree &&
121
142
rm -f " $TMPindex "
@@ -129,7 +150,7 @@ create_stash () {
129
150
130
151
# find out what the user wants
131
152
GIT_INDEX_FILE=" $TMP -index" \
132
- git add--interactive --patch=stash -- &&
153
+ git add--interactive --patch=stash -- " $@ " &&
133
154
134
155
# state of the working tree
135
156
w_tree=$( GIT_INDEX_FILE=" $TMP -index" git write-tree) ||
@@ -189,10 +210,11 @@ store_stash () {
189
210
return $ret
190
211
}
191
212
192
- save_stash () {
213
+ push_stash () {
193
214
keep_index=
194
215
patch_mode=
195
216
untracked=
217
+ stash_msg=
196
218
while test $# ! = 0
197
219
do
198
220
case " $1 " in
@@ -216,6 +238,11 @@ save_stash () {
216
238
-a|--all)
217
239
untracked=all
218
240
;;
241
+ -m|--message)
242
+ shift
243
+ test -z ${1+x} && usage
244
+ stash_msg=$1
245
+ ;;
219
246
--help)
220
247
show_help
221
248
;;
@@ -251,29 +278,38 @@ save_stash () {
251
278
die " $( gettext " Can't use --patch and --include-untracked or --all at the same time" ) "
252
279
fi
253
280
254
- stash_msg= " $* "
281
+ test -n " $untracked " || git ls-files --error-unmatch -- " $@ " > /dev/null || exit 1
255
282
256
283
git update-index -q --refresh
257
- if no_changes
284
+ if no_changes " $@ "
258
285
then
259
286
say " $( gettext " No local changes to save" ) "
260
287
exit 0
261
288
fi
289
+
262
290
git reflog exists $ref_stash ||
263
291
clear_stash || die " $( gettext " Cannot initialize stash" ) "
264
292
265
- create_stash " $stash_msg " $untracked
293
+ create_stash -m " $stash_msg " -u " $untracked " -- " $@ "
266
294
store_stash -m " $stash_msg " -q $w_commit ||
267
295
die " $( gettext " Cannot save the current status" ) "
268
296
say " $( eval_gettext " Saved working directory and index state \$ stash_msg" ) "
269
297
270
298
if test -z " $patch_mode "
271
299
then
272
- git reset --hard ${GIT_QUIET: +-q}
300
+ if test $# ! = 0
301
+ then
302
+ git reset ${GIT_QUIET: +-q} -- " $@ "
303
+ git ls-files -z --modified -- " $@ " |
304
+ git checkout-index -z --force --stdin
305
+ git clean --force ${GIT_QUIET: +-q} -d -- " $@ "
306
+ else
307
+ git reset --hard ${GIT_QUIET: +-q}
308
+ fi
273
309
test " $untracked " = " all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
274
310
if test -n " $untracked "
275
311
then
276
- git clean --force --quiet -d $CLEAN_X_OPTION
312
+ git clean --force --quiet -d $CLEAN_X_OPTION -- " $@ "
277
313
fi
278
314
279
315
if test " $keep_index " = " t" && test -n " $i_tree "
@@ -291,6 +327,36 @@ save_stash () {
291
327
fi
292
328
}
293
329
330
+ save_stash () {
331
+ push_options=
332
+ while test $# ! = 0
333
+ do
334
+ case " $1 " in
335
+ --)
336
+ shift
337
+ break
338
+ ;;
339
+ -* )
340
+ # pass all options through to push_stash
341
+ push_options=" $push_options $1 "
342
+ ;;
343
+ * )
344
+ break
345
+ ;;
346
+ esac
347
+ shift
348
+ done
349
+
350
+ stash_msg=" $* "
351
+
352
+ if test -z " $stash_msg "
353
+ then
354
+ push_stash $push_options
355
+ else
356
+ push_stash $push_options -m " $stash_msg "
357
+ fi
358
+ }
359
+
294
360
have_stash () {
295
361
git rev-parse --verify --quiet $ref_stash > /dev/null
296
362
}
@@ -590,18 +656,21 @@ apply_to_branch () {
590
656
}
591
657
}
592
658
659
+ test " $1 " = " -p" && set " push" " $@ "
660
+
593
661
PARSE_CACHE=' --not-parsed'
594
- # The default command is "save " if nothing but options are given
662
+ # The default command is "push " if nothing but options are given
595
663
seen_non_option=
596
664
for opt
597
665
do
598
666
case " $opt " in
667
+ --) break ;;
599
668
-* ) ;;
600
669
* ) seen_non_option=t; break ;;
601
670
esac
602
671
done
603
672
604
- test -n " $seen_non_option " || set " save " " $@ "
673
+ test -n " $seen_non_option " || set " push " " $@ "
605
674
606
675
# Main command set
607
676
case " $1 " in
@@ -617,6 +686,10 @@ save)
617
686
shift
618
687
save_stash " $@ "
619
688
;;
689
+ push)
690
+ shift
691
+ push_stash " $@ "
692
+ ;;
620
693
apply)
621
694
shift
622
695
apply_stash " $@ "
@@ -627,7 +700,7 @@ clear)
627
700
;;
628
701
create)
629
702
shift
630
- create_stash " $* " && echo " $w_commit "
703
+ create_stash -m " $* " && echo " $w_commit "
631
704
;;
632
705
store)
633
706
shift
@@ -648,7 +721,7 @@ branch)
648
721
* )
649
722
case $# in
650
723
0)
651
- save_stash &&
724
+ push_stash &&
652
725
say " $( gettext " (To restore them type \" git stash apply\" )" ) "
653
726
;;
654
727
* )
0 commit comments