]> rtime.felk.cvut.cz Git - git.git/blobdiff - git-stash.sh
Merge branch 'jk/maint-pull-dry-run-noop'
[git.git] / git-stash.sh
index 0726a4a725d75212539c9fce9e657de04bc227c3..1d95447d03f342811dd77386f2e83d0814beabf2 100755 (executable)
@@ -86,7 +86,7 @@ create_stash () {
                        GIT_INDEX_FILE="$TMP-index" &&
                        export GIT_INDEX_FILE &&
                        git read-tree -m $i_tree &&
-                       git add -u &&
+                       git diff --name-only -z HEAD | git update-index -z --add --remove --stdin &&
                        git write-tree &&
                        rm -f "$TMP-index"
                ) ) ||
@@ -151,6 +151,7 @@ save_stash () {
                        ;;
                -*)
                        echo "error: unknown option for 'stash save': $1"
+                       echo "       To provide a message, use git stash save -- '$1'"
                        usage
                        ;;
                *)
@@ -209,18 +210,23 @@ 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 --verify --default $ref_stash "$@") &&
-       b_commit=$(git rev-parse --verify "$w_commit^") &&
+       w_commit=$(git rev-parse --quiet --verify --default $ref_stash "$@") &&
+       b_commit=$(git rev-parse --quiet --verify "$w_commit^") ||
+               die "'$*' is not a stash"
+
        git diff $flags $b_commit $w_commit
 }
 
 apply_stash () {
+       applied_stash=
        unstash_index=
 
        while test $# != 0
@@ -242,6 +248,9 @@ apply_stash () {
        if test $# = 0
        then
                have_stash || die 'Nothing to apply'
+               applied_stash="$ref_stash@{0}"
+       else
+               applied_stash="$*"
        fi
 
        # stash records the work tree, and is a merge between the
@@ -415,8 +424,7 @@ pop)
        shift
        if apply_stash "$@"
        then
-               test -z "$unstash_index" || shift
-               drop_stash "$@"
+               drop_stash "$applied_stash"
        fi
        ;;
 branch)