diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-08-25 14:46:04 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-08-25 14:46:04 -0700 |
commit | b91069ae9a6cb2d92fa6a5ed6d258bed530abcc7 (patch) | |
tree | 6c3f0bfa27a74582b871db34752424108b2e8d6e | |
parent | b85e6c5f8107c802c627981e044e680999884c5f (diff) | |
parent | 5fd448f1142c61da31b28c74d7d340938ab0e01d (diff) | |
download | git-b91069ae9a6cb2d92fa6a5ed6d258bed530abcc7.tar.gz git-b91069ae9a6cb2d92fa6a5ed6d258bed530abcc7.tar.xz |
Merge branch 'oa/stash-na'
* oa/stash-na:
git stash: Give friendlier errors when there is nothing to apply
-rwxr-xr-x | git-stash.sh | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/git-stash.sh b/git-stash.sh index 03e589f76..d61c9d03b 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -162,10 +162,6 @@ show_stash () { } apply_stash () { - git update-index -q --refresh && - git diff-files --quiet --ignore-submodules || - die 'Cannot apply to a dirty working tree, please stage your changes' - unstash_index= while test $# != 0 @@ -184,18 +180,27 @@ apply_stash () { shift done - # current index state - c_tree=$(git write-tree) || - die 'Cannot apply a stash in the middle of a merge' + if test $# = 0 + then + have_stash || die 'Nothing to apply' + fi # stash records the work tree, and is a merge between the # base commit (first parent) and the index tree (second parent). - s=$(git rev-parse --verify --default $ref_stash "$@") && - w_tree=$(git rev-parse --verify "$s:") && - b_tree=$(git rev-parse --verify "$s^1:") && - i_tree=$(git rev-parse --verify "$s^2:") || + s=$(git rev-parse --quiet --verify --default $ref_stash "$@") && + w_tree=$(git rev-parse --quiet --verify "$s:") && + b_tree=$(git rev-parse --quiet --verify "$s^1:") && + i_tree=$(git rev-parse --quiet --verify "$s^2:") || die "$*: no valid stashed state found" + git update-index -q --refresh && + git diff-files --quiet --ignore-submodules || + die 'Cannot apply to a dirty working tree, please stage your changes' + + # current index state + c_tree=$(git write-tree) || + die 'Cannot apply a stash in the middle of a merge' + unstashed_index_tree= if test -n "$unstash_index" && test "$b_tree" != "$i_tree" && test "$c_tree" != "$i_tree" |