Code

Make 'git stash -k' a short form for 'git stash save --keep-index'
[git.git] / git-stash.sh
index 531c7c31aca87db77e54c46ffb89899652a79fcd..13edc0eefd56507930055f57fa48c3bfb6863108 100755 (executable)
@@ -7,7 +7,8 @@ USAGE="list [<options>]
    or: $dashless drop [-q|--quiet] [<stash>]
    or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
    or: $dashless branch <branchname> [<stash>]
-   or: $dashless [save [--keep-index] [-q|--quiet] [<message>]]
+   or: $dashless [save [-k|--keep-index] [-q|--quiet] [<message>]]
+   or: $dashless [-k|--keep-index]
    or: $dashless clear"
 
 SUBDIRECTORY_OK=Yes
@@ -98,7 +99,7 @@ save_stash () {
        while test $# != 0
        do
                case "$1" in
-               --keep-index)
+               -k|--keep-index)
                        keep_index=t
                        ;;
                -q|--quiet)
@@ -203,7 +204,7 @@ apply_stash () {
                git diff-tree --binary $s^2^..$s^2 | git apply --cached
                test $? -ne 0 &&
                        die 'Conflicts in index. Try without --index.'
-               unstashed_index_tree=$(git-write-tree) ||
+               unstashed_index_tree=$(git write-tree) ||
                        die 'Could not save index tree'
                git reset
        fi
@@ -219,7 +220,7 @@ apply_stash () {
        then
                export GIT_MERGE_VERBOSITY=0
        fi
-       if git-merge-recursive $b_tree -- $c_tree $w_tree
+       if git merge-recursive $b_tree -- $c_tree $w_tree
        then
                # No conflict
                if test -n "$unstashed_index_tree"
@@ -297,7 +298,7 @@ apply_to_branch () {
        fi
        stash=$2
 
-       git-checkout -b $branch $stash^ &&
+       git checkout -b $branch $stash^ &&
        apply_stash --index $stash &&
        drop_stash $stash
 }
@@ -353,12 +354,13 @@ branch)
        apply_to_branch "$@"
        ;;
 *)
-       if test $# -eq 0
-       then
-               save_stash &&
+       case $#,"$1" in
+       0,|1,-k|1,--keep-index)
+               save_stash "$@" &&
                say '(To restore them type "git stash apply")'
-       else
+               ;;
+       *)
                usage
-       fi
+       esac
        ;;
 esac