@@ -11,6 +11,7 @@ USAGE="list [<options>]
1111 [-u|--include-untracked] [-a|--all] [<message>]]
1212 or: $dashless push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
1313 [-u|--include-untracked] [-a|--all] [-m <message>]
14+ [-- <pathspec>...]
1415 or: $dashless clear"
1516
1617SUBDIRECTORY_OK=Yes
3536fi
3637
3738no_changes () {
38- git diff-index --quiet --cached HEAD --ignore-submodules -- &&
39- git diff-files --quiet --ignore-submodules &&
39+ git diff-index --quiet --cached HEAD --ignore-submodules -- " $@ " &&
40+ git diff-files --quiet --ignore-submodules -- " $@ " &&
4041 (test -z " $untracked " || test -z " $( untracked_files) " )
4142}
4243
4344untracked_files () {
4445 excl_opt=--exclude-standard
4546 test " $untracked " = " all" && excl_opt=
46- git ls-files -o -z $excl_opt
47+ git ls-files -o -z $excl_opt -- " $@ "
4748}
4849
4950clear_stash () {
@@ -71,12 +72,16 @@ create_stash () {
7172 shift
7273 untracked=${1?" BUG: create_stash () -u requires an argument" }
7374 ;;
75+ --)
76+ shift
77+ break
78+ ;;
7479 esac
7580 shift
7681 done
7782
7883 git update-index -q --refresh
79- if no_changes
84+ if no_changes " $@ "
8085 then
8186 exit 0
8287 fi
@@ -108,7 +113,7 @@ create_stash () {
108113 # Untracked files are stored by themselves in a parentless commit, for
109114 # ease of unpacking later.
110115 u_commit=$(
111- untracked_files | (
116+ untracked_files " $@ " | (
112117 GIT_INDEX_FILE=" $TMPindex " &&
113118 export GIT_INDEX_FILE &&
114119 rm -f " $TMPindex " &&
@@ -131,7 +136,7 @@ create_stash () {
131136 git read-tree --index-output=" $TMPindex " -m $i_tree &&
132137 GIT_INDEX_FILE=" $TMPindex " &&
133138 export GIT_INDEX_FILE &&
134- git diff-index --name-only -z HEAD -- > " $TMP -stagenames" &&
139+ git diff-index --name-only -z HEAD -- " $@ " > " $TMP -stagenames" &&
135140 git update-index -z --add --remove --stdin < " $TMP -stagenames" &&
136141 git write-tree &&
137142 rm -f " $TMPindex "
@@ -145,7 +150,7 @@ create_stash () {
145150
146151 # find out what the user wants
147152 GIT_INDEX_FILE=" $TMP -index" \
148- git add--interactive --patch=stash -- &&
153+ git add--interactive --patch=stash -- " $@ " &&
149154
150155 # state of the working tree
151156 w_tree=$( GIT_INDEX_FILE=" $TMP -index" git write-tree) ||
@@ -273,27 +278,38 @@ push_stash () {
273278 die " $( gettext " Can't use --patch and --include-untracked or --all at the same time" ) "
274279 fi
275280
281+ test -n " $untracked " || git ls-files --error-unmatch -- " $@ " > /dev/null || exit 1
282+
276283 git update-index -q --refresh
277- if no_changes
284+ if no_changes " $@ "
278285 then
279286 say " $( gettext " No local changes to save" ) "
280287 exit 0
281288 fi
289+
282290 git reflog exists $ref_stash ||
283291 clear_stash || die " $( gettext " Cannot initialize stash" ) "
284292
285- create_stash -m " $stash_msg " -u " $untracked "
293+ create_stash -m " $stash_msg " -u " $untracked " -- " $@ "
286294 store_stash -m " $stash_msg " -q $w_commit ||
287295 die " $( gettext " Cannot save the current status" ) "
288296 say " $( eval_gettext " Saved working directory and index state \$ stash_msg" ) "
289297
290298 if test -z " $patch_mode "
291299 then
292- 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
293309 test " $untracked " = " all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
294310 if test -n " $untracked "
295311 then
296- git clean --force --quiet -d $CLEAN_X_OPTION
312+ git clean --force --quiet -d $CLEAN_X_OPTION -- " $@ "
297313 fi
298314
299315 if test " $keep_index " = " t" && test -n " $i_tree "
0 commit comments