summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Avtalion <ori@avtalion.name>2009-08-11 11:12:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-08-15 02:48:45 (GMT)
commit5fd448f1142c61da31b28c74d7d340938ab0e01d (patch)
tree3da959b86fb5aa56aa9940332c99a1114c824ead
parent6ffd781226f04629eff63a684b47ad7555143312 (diff)
downloadgit-5fd448f1142c61da31b28c74d7d340938ab0e01d.zip
git-5fd448f1142c61da31b28c74d7d340938ab0e01d.tar.gz
git-5fd448f1142c61da31b28c74d7d340938ab0e01d.tar.bz2
git stash: Give friendlier errors when there is nothing to apply
The change makes sure a stash (given or default) exists before checking if the working tree is dirty. If the default stash is requested, the old message was scary and included a 'fatal' error from rev-parse: fatal: Needed a single revision : no valid stashed state found It is replaced with a friendlier 'Nothing to apply' error, similar to 'git stash branch'. If a specific stash is specified, the 'Needed a single revision' errors from rev-parse are suppressed. Signed-off-by: Ori Avtalion <ori@avtalion.name> Acked-by: Thomas Rast <trast@student.ethz.ch> Acked-by: Nanako Shiraishi <nanako3@lavabit.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-xgit-stash.sh27
1 files changed, 16 insertions, 11 deletions
diff --git a/git-stash.sh b/git-stash.sh
index 03e589f..d61c9d0 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"