]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-stash.sh
Make some of fwrite/fclose/write/close failures visible
[git.git] / git-stash.sh
index 6bd2572f7745cbd35fb59c3449b84f1929d9ab08..c0532e8751d361d2875f87a43ff5a519ea7e08ea 100755 (executable)
@@ -30,7 +30,7 @@ clear_stash () {
        then
                die "git stash clear with parameters is unimplemented"
        fi
-       if current=$(git rev-parse --verify $ref_stash 2>/dev/null)
+       if current=$(git rev-parse -q --verify $ref_stash)
        then
                git update-ref -d $ref_stash $current
        fi
@@ -129,7 +129,7 @@ save_stash () {
 }
 
 have_stash () {
-       git rev-parse --verify $ref_stash >/dev/null 2>&1
+       git rev-parse -q --verify $ref_stash >/dev/null
 }
 
 list_stash () {
@@ -145,23 +145,15 @@ show_stash () {
                flags=--stat
        fi
 
-       if test $# = 0
-       then
-               set x "$ref_stash@{0}"
-               shift
-       fi
-
-       s=$(git rev-parse --revs-only --no-flags "$@")
-
-       w_commit=$(git rev-parse --verify "$s") &&
-       b_commit=$(git rev-parse --verify "$s^") &&
+       w_commit=$(git rev-parse --verify --default $ref_stash "$@") &&
+       b_commit=$(git rev-parse --verify "$w_commit^") &&
        git diff $flags $b_commit $w_commit
 }
 
 apply_stash () {
        git update-index -q --refresh &&
        git diff-files --quiet --ignore-submodules ||
-               die 'Cannot restore on top of a dirty state'
+               die 'Cannot apply to a dirty working tree, please stage your changes'
 
        unstash_index=
        case "$1" in
@@ -170,19 +162,13 @@ apply_stash () {
                shift
        esac
 
-       if test $# = 0
-       then
-               set x "$ref_stash@{0}"
-               shift
-       fi
-
        # current index state
        c_tree=$(git write-tree) ||
                die 'Cannot apply a stash in the middle of a merge'
 
        # 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 --revs-only --no-flags "$@") &&
+       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:") ||
@@ -242,17 +228,17 @@ drop_stash () {
                shift
        fi
        # Verify supplied argument looks like a stash entry
-       s=$(git rev-parse --revs-only --no-flags "$@") &&
-       git rev-parse --verify "$s:"   > /dev/null 2>&1 &&
-       git rev-parse --verify "$s^1:" > /dev/null 2>&1 &&
-       git rev-parse --verify "$s^2:" > /dev/null 2>&1 ||
+       s=$(git rev-parse --verify "$@") &&
+       git rev-parse -q --verify "$s:"   > /dev/null &&
+       git rev-parse -q --verify "$s^1:" > /dev/null &&
+       git rev-parse -q --verify "$s^2:" > /dev/null ||
                die "$*: not a valid stashed state"
 
        git reflog delete --updateref --rewrite "$@" &&
                echo "Dropped $* ($s)" || die "$*: Could not drop stash entry"
 
        # clear_stash if we just dropped the last stash entry
-       git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
+       git rev-parse -q --verify "$ref_stash@{0}" > /dev/null || clear_stash
 }
 
 apply_to_branch () {