7
or: $dashless drop [-q|--quiet] [<stash>]
8
or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
9
or: $dashless branch <branchname> [<stash>]
10
- or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] [<message>]]
10
+ or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
11
+ [-u|--include-untracked] [-a|--all] [<message>]]
12
or: $dashless clear"
13
14
SUBDIRECTORY_OK=Yes
34
35
no_changes () {
36
git diff-index --quiet --cached HEAD --ignore-submodules -- &&
36
- git diff-files --quiet --ignore-submodules
37
+ git diff-files --quiet --ignore-submodules &&
38
+ (test -z "$untracked" || test -z "$(untracked_files)")
39
+}
40
+
41
+untracked_files () {
42
+ excl_opt=--exclude-standard
43
+ test "$untracked" = "all" && excl_opt=
44
+ git ls-files -o -z $excl_opt
45
}
46
47
clear_stash () {
57
58
create_stash () {
59
stash_msg="$1"
60
+ untracked="$2"
61
62
git update-index -q --refresh
63
if no_changes
87
git commit-tree $i_tree -p $b_commit) ||
88
die "Cannot save the current index state"
89
90
+ if test -n "$untracked"
91
+ then
92
+ # Untracked files are stored by themselves in a parentless commit, for
93
+ # ease of unpacking later.
94
+ u_commit=$(
95
+ untracked_files | (
96
+ export GIT_INDEX_FILE="$TMPindex"
97
+ rm -f "$TMPindex" &&
98
+ git update-index -z --add --remove --stdin &&
99
+ u_tree=$(git write-tree) &&
100
+ printf 'untracked files on %s\n' "$msg" | git commit-tree $u_tree &&
101
+ rm -f "$TMPindex"
102
+ ) ) || die "Cannot save the untracked files"
103
+
104
+ untracked_commit_option="-p $u_commit";
105
+ else
106
+ untracked_commit_option=
107
+ fi
108
+
109
if test -z "$patch_mode"
110
then
111
150
stash_msg=$(printf 'On %s: %s' "$branch" "$stash_msg")
151
fi
152
w_commit=$(printf '%s\n' "$stash_msg" |
125
- git commit-tree $w_tree -p $b_commit -p $i_commit) ||
153
+ git commit-tree $w_tree -p $b_commit -p $i_commit $untracked_commit_option) ||
154
die "Cannot record working tree state"
155
}
156
157
save_stash () {
158
keep_index=
159
patch_mode=
160
+ untracked=
161
while test $# != 0
162
do
163
case "$1" in
175
-q|--quiet)
176
GIT_QUIET=t
177
;;
178
+ -u|--include-untracked)
179
+ untracked=untracked
180
+ ;;
181
+ -a|--all)
182
+ untracked=all
183
+ ;;
184
--)
185
shift
186
break
197
shift
198
done
199
200
+ if test -n "$patch_mode" && test -n "$untracked"
201
+ then
202
+ die "Can't use --patch and ---include-untracked or --all at the same time"
203
+ fi
204
+
205
stash_msg="$*"
206
207
git update-index -q --refresh
213
test -f "$GIT_DIR/logs/$ref_stash" ||
214
clear_stash || die "Cannot initialize stash"
215
176
- create_stash "$stash_msg"
216
+ create_stash "$stash_msg" $untracked
217
218
# Make sure the reflog for stash is kept.
219
: >>"$GIT_DIR/logs/$ref_stash"
225
if test -z "$patch_mode"
226
then
227
git reset --hard ${GIT_QUIET:+-q}
228
+ test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
229
+ if test -n "$untracked"
230
+ then
231
+ git clean --force --quiet $CLEAN_X_OPTION
232
+ fi
233
234
if test "$keep_index" = "t" && test -n $i_tree
235
then
279
# w_commit is set to the commit containing the working tree
280
# b_commit is set to the base commit
281
# i_commit is set to the commit containing the index tree
282
+# u_commit is set to the commit containing the untracked files tree
283
# w_tree is set to the working tree
284
# b_tree is set to the base tree
285
# i_tree is set to the index tree
286
+# u_tree is set to the untracked files tree
287
#
288
# GIT_QUIET is set to t if -q is specified
289
# INDEX_OPTION is set to --index if --index is specified.
308
w_commit=
309
b_commit=
310
i_commit=
311
+ u_commit=
312
w_tree=
313
b_tree=
314
i_tree=
315
+ u_tree=
316
317
REV=$(git rev-parse --no-flags --symbolic "$@") || exit 1
318
360
IS_STASH_LIKE=t &&
361
test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
362
IS_STASH_REF=t
363
+
364
+ u_commit=$(git rev-parse --quiet --verify $REV^3 2>/dev/null) &&
365
+ u_tree=$(git rev-parse $REV^3: 2>/dev/null)
366
}
367
368
is_stash_like()
405
git reset
406
fi
407
408
+ if test -n "$u_tree"
409
+ then
410
+ GIT_INDEX_FILE="$TMPindex" git-read-tree "$u_tree" &&
411
+ GIT_INDEX_FILE="$TMPindex" git checkout-index --all &&
412
+ rm -f "$TMPindex" ||
413
+ die 'Could not restore untracked files from stash'
414
+ fi
415
+
416
eval "
417
GITHEAD_$w_tree='Stashed changes' &&
418
GITHEAD_$c_tree='Updated upstream' &&