Skip to contentSkip to conversation

Make 'git stash -k' a short form for 'git stash save --keep-index'

PATCH In review Johannes Schindelin 2 participants 4 messages Jun 15, 2016 1 message not in the archive Documentation

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 Make 'git stash -k' a short form for 'git stash save --keep-index'

In reply to a message not in the archive

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.

---
 Documentation/git-stash.txt |    3 ++-
 git-stash.sh                |   16 +++++++++-------
 t/t3903-stash.sh            |    8 ++++++++
 3 files changed, 19 insertions(+), 8 deletions(-)
Documentation/git-stash.txt +2 -1
index 1c64a02..a031836 100644
@@ -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
 
git-stash.sh +9 -7
index 03e589f..13edc0e 100755
@@ -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
t/t3903-stash.sh +8 -0
index 7a3fb67..e16ad93 100755
@@ -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
Signature · 1 line
1.6.3.2.734.g770e
#2 lore raw

Heya,

Quoted 4 lines · Johannes Schindelin

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.

+many, especially the DWIM part! Does it also grok 'git stash --keep-index'?

Signature · 3 lines
Cheers,

Sverre Rabbelier
#3 lore raw

Hi,

Quoted 9 lines · Sverre Rabbelier
Quoted 4 lines · Johannes Schindelin

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.

+many, especially the DWIM part! Does it also grok 'git stash --keep-index'?

Yes, it does, but it causes carpal tunnel.

Ciao,
Dscho

#4 lore raw

Heya,

Quoted 1 line · Johannes Schindelin

Yes, it does, but it causes carpal tunnel.

True that, but it's consistent at least :).

Signature · 3 lines
Cheers,

Sverre Rabbelier