@@ -162,10 +162,6 @@ show_stash () {
162
162
}
163
163
164
164
apply_stash () {
165
- git update-index -q --refresh &&
166
- git diff-files --quiet --ignore-submodules ||
167
- die ' Cannot apply to a dirty working tree, please stage your changes'
168
-
169
165
unstash_index=
170
166
171
167
while test $# ! = 0
@@ -184,18 +180,27 @@ apply_stash () {
184
180
shift
185
181
done
186
182
187
- # current index state
188
- c_tree=$( git write-tree) ||
189
- die ' Cannot apply a stash in the middle of a merge'
183
+ if test $# = 0
184
+ then
185
+ have_stash || die ' Nothing to apply'
186
+ fi
190
187
191
188
# stash records the work tree, and is a merge between the
192
189
# base commit (first parent) and the index tree (second parent).
193
- s=$( git rev-parse --verify --default $ref_stash " $@ " ) &&
194
- w_tree=$( git rev-parse --verify " $s :" ) &&
195
- b_tree=$( git rev-parse --verify " $s ^1:" ) &&
196
- i_tree=$( git rev-parse --verify " $s ^2:" ) ||
190
+ s=$( git rev-parse --quiet -- verify --default $ref_stash " $@ " ) &&
191
+ w_tree=$( git rev-parse --quiet -- verify " $s :" ) &&
192
+ b_tree=$( git rev-parse --quiet -- verify " $s ^1:" ) &&
193
+ i_tree=$( git rev-parse --quiet -- verify " $s ^2:" ) ||
197
194
die " $* : no valid stashed state found"
198
195
196
+ git update-index -q --refresh &&
197
+ git diff-files --quiet --ignore-submodules ||
198
+ die ' Cannot apply to a dirty working tree, please stage your changes'
199
+
200
+ # current index state
201
+ c_tree=$( git write-tree) ||
202
+ die ' Cannot apply a stash in the middle of a merge'
203
+
199
204
unstashed_index_tree=
200
205
if test -n " $unstash_index " && test " $b_tree " ! = " $i_tree " &&
201
206
test " $c_tree " ! = " $i_tree "
0 commit comments