Code

Make 'git stash -k' a short form for 'git stash save --keep-index'
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 27 Jul 2009 18:37:10 +0000 (20:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 31 Jul 2009 14:33:06 +0000 (07:33 -0700)
To save me from the carpal tunnel syndrome, make 'git stash' accept
the short option '-k' instead of '--keep-index', and for even more
convenience, let's DWIM when this developer forgot to type the 'save'
command.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-stash.txt
git-stash.sh
t/t3903-stash.sh

index 1c64a02fe576a6bdad2afcbc96391ce0c2d541c4..a031836a26c562deb490819f9a7fe7e0c0034e9f 100644 (file)
@@ -13,7 +13,8 @@ SYNOPSIS
 'git stash' drop [-q|--quiet] [<stash>]
 'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
 'git stash' branch <branchname> [<stash>]
-'git stash' [save [--keep-index] [-q|--quiet] [<message>]]
+'git stash' [save [-k|--keep-index] [-q|--quiet] [<message>]]
+'git stash' [-k|--keep-index]
 'git stash' clear
 'git stash' create
 
index 03e589f764ba0570559fdb23a9a11cc2a0f24044..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)
@@ -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
index 7a3fb679571a9fc79135f8b9495462f723b663af..e16ad93d2c2718baf62ad90e9fc07187106d9ee4 100755 (executable)
@@ -200,4 +200,12 @@ test_expect_success 'drop -q is quiet' '
        test ! -s output.out
 '
 
+test_expect_success 'stash -k' '
+       echo bar3 > file &&
+       echo bar4 > file2 &&
+       git add file2 &&
+       git stash -k &&
+       test bar,bar4 = $(cat file),$(cat file2)
+'
+
 test_done