]> Pileus Git - ~andy/git/blobdiff - git-stash.sh
git-send-email.perl: ensure $domain is defined before using it
[~andy/git] / git-stash.sh
index 750f360da9730423fde863de391ecbe550b172cf..57f36ce8dd7cd25e269f8e31d6fdc668d62811f9 100755 (executable)
@@ -210,19 +210,9 @@ list_stash () {
 }
 
 show_stash () {
-       have_stash || die 'No stash found'
-
-       flags=$(git rev-parse --no-revs --flags "$@")
-       if test -z "$flags"
-       then
-               flags=--stat
-       fi
-
-       w_commit=$(git rev-parse --quiet --verify --default $ref_stash "$@") &&
-       b_commit=$(git rev-parse --quiet --verify "$w_commit^") ||
-               die "'$*' is not a stash"
+       assert_stash_like "$@"
 
-       git diff $flags $b_commit $w_commit
+       git diff ${FLAGS:---stat} $b_commit $w_commit
 }
 
 #
@@ -274,8 +264,18 @@ parse_flags_and_rev()
        b_tree=
        i_tree=
 
+       # Work around rev-parse --flags eating -q
+       for opt
+       do
+               case "$opt" in
+               -q|--quiet)
+                       GIT_QUIET=t
+                       ;;
+               esac
+       done
+
        REV=$(git rev-parse --no-flags --symbolic "$@" 2>/dev/null)
-       FLAGS=$(git rev-parse --no-revs -- "$@" 2>/dev/null)
+       FLAGS=$(git rev-parse --no-revs --flags "$@" 2>/dev/null)
 
        set -- $FLAGS
 
@@ -283,9 +283,6 @@ parse_flags_and_rev()
        while test $# -ne 0
        do
                case "$1" in
-                       -q|--quiet)
-                               GIT_QUIET=-t
-                       ;;
                        --index)
                                INDEX_OPTION=--index
                        ;;
@@ -423,6 +420,13 @@ apply_stash () {
        fi
 }
 
+pop_stash() {
+       assert_stash_ref "$@"
+
+       apply_stash "$@" &&
+       drop_stash "$@"
+}
+
 drop_stash () {
        assert_stash_ref "$@"
 
@@ -434,20 +438,17 @@ drop_stash () {
 }
 
 apply_to_branch () {
-       have_stash || die 'Nothing to apply'
-
        test -n "$1" || die 'No branch name specified'
        branch=$1
+       shift 1
 
-       if test -z "$2"
-       then
-               set x "$ref_stash@{0}"
-       fi
-       stash=$2
+       set -- --index "$@"
+       assert_stash_like "$@"
+
+       git checkout -b $branch $REV^ &&
+       apply_stash "$@"
 
-       git checkout -b $branch $stash^ &&
-       apply_stash --index $stash &&
-       drop_stash $stash
+       test -z "$IS_STASH_REF" || drop_stash "$@"
 }
 
 PARSE_CACHE='--not-parsed'
@@ -498,10 +499,7 @@ drop)
        ;;
 pop)
        shift
-       if apply_stash "$@"
-       then
-               drop_stash "$applied_stash"
-       fi
+       pop_stash "$@"
        ;;
 branch)
        shift