Skip to content

Commit ea41cfc

Browse files
dschogitster
authored andcommitted
Make 'git stash -k' a short form for 'git stash save --keep-index'
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6517452 commit ea41cfc

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Documentation/git-stash.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ SYNOPSIS
1313
'git stash' drop [-q|--quiet] [<stash>]
1414
'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
1515
'git stash' branch <branchname> [<stash>]
16-
'git stash' [save [--keep-index] [-q|--quiet] [<message>]]
16+
'git stash' [save [-k|--keep-index] [-q|--quiet] [<message>]]
17+
'git stash' [-k|--keep-index]
1718
'git stash' clear
1819
'git stash' create
1920

git-stash.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ USAGE="list [<options>]
77
or: $dashless drop [-q|--quiet] [<stash>]
88
or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
99
or: $dashless branch <branchname> [<stash>]
10-
or: $dashless [save [--keep-index] [-q|--quiet] [<message>]]
10+
or: $dashless [save [-k|--keep-index] [-q|--quiet] [<message>]]
11+
or: $dashless [-k|--keep-index]
1112
or: $dashless clear"
1213

1314
SUBDIRECTORY_OK=Yes
@@ -98,7 +99,7 @@ save_stash () {
9899
while test $# != 0
99100
do
100101
case "$1" in
101-
--keep-index)
102+
-k|--keep-index)
102103
keep_index=t
103104
;;
104105
-q|--quiet)
@@ -353,12 +354,13 @@ branch)
353354
apply_to_branch "$@"
354355
;;
355356
*)
356-
if test $# -eq 0
357-
then
358-
save_stash &&
357+
case $#,"$1" in
358+
0,|1,-k|1,--keep-index)
359+
save_stash "$@" &&
359360
say '(To restore them type "git stash apply")'
360-
else
361+
;;
362+
*)
361363
usage
362-
fi
364+
esac
363365
;;
364366
esac

t/t3903-stash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,12 @@ test_expect_success 'drop -q is quiet' '
200200
test ! -s output.out
201201
'
202202

203+
test_expect_success 'stash -k' '
204+
echo bar3 > file &&
205+
echo bar4 > file2 &&
206+
git add file2 &&
207+
git stash -k &&
208+
test bar,bar4 = $(cat file),$(cat file2)
209+
'
210+
203211
test_done

0 commit comments

Comments
 (0)