@@ -162,10 +162,6 @@ show_stash () {
162162}
163163
164164apply_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-
169165 unstash_index=
170166
171167 while test $# ! = 0
@@ -184,18 +180,27 @@ apply_stash () {
184180 shift
185181 done
186182
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
190187
191188 # stash records the work tree, and is a merge between the
192189 # 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:" ) ||
197194 die " $* : no valid stashed state found"
198195
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+
199204 unstashed_index_tree=
200205 if test -n " $unstash_index " && test " $b_tree " ! = " $i_tree " &&
201206 test " $c_tree " ! = " $i_tree "
0 commit comments