]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-stash.sh
"git-merge": allow fast-forwarding in a stat-dirty tree
[git.git] / git-stash.sh
index 889445c4fc8ce523558644484de559d40229fc01..e15c12abc31c1e4d22bb3943d70a65ddf33abb53 100755 (executable)
@@ -1,7 +1,13 @@
 #!/bin/sh
 # Copyright (c) 2007, Nanako Shiraishi
 
-USAGE='[  | save | list | show | apply | clear | drop | pop | create ]'
+dashless=$(basename "$0" | sed -e 's/-/ /')
+USAGE="list [<options>]
+   or: $dashless (show | drop | pop ) [<stash>]
+   or: $dashless apply [--index] [<stash>]
+   or: $dashless branch <branchname> [<stash>]
+   or: $dashless [save [--keep-index] [<message>]]
+   or: $dashless clear"
 
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
@@ -86,7 +92,14 @@ create_stash () {
 }
 
 save_stash () {
-       stash_msg="$1"
+       keep_index=
+       case "$1" in
+       --keep-index)
+               keep_index=t
+               shift
+       esac
+
+       stash_msg="$*"
 
        if no_changes
        then
@@ -104,6 +117,13 @@ save_stash () {
        git update-ref -m "$stash_msg" $ref_stash $w_commit ||
                die "Cannot save the current status"
        printf 'Saved working directory and index state "%s"\n' "$stash_msg"
+
+       git reset --hard
+
+       if test -n "$keep_index" && test -n $i_tree
+       then
+               git read-tree --reset -u $i_tree
+       fi
 }
 
 have_stash () {
@@ -153,7 +173,8 @@ apply_stash () {
                die "$*: no valid stashed state found"
 
        unstashed_index_tree=
-       if test -n "$unstash_index" && test "$b_tree" != "$i_tree"
+       if test -n "$unstash_index" && test "$b_tree" != "$i_tree" &&
+                       test "$c_tree" != "$i_tree"
        then
                git diff-tree --binary $s^2^..$s^2 | git apply --cached
                test $? -ne 0 &&
@@ -252,7 +273,7 @@ show)
        ;;
 save)
        shift
-       save_stash "$*" && git-reset --hard
+       save_stash "$@"
        ;;
 apply)
        shift
@@ -289,8 +310,7 @@ branch)
        if test $# -eq 0
        then
                save_stash &&
-               echo '(To restore them type "git stash apply")' &&
-               git-reset --hard
+               echo '(To restore them type "git stash apply")'
        else
                usage
        fi