Skip to content

Commit 5675473

Browse files
phordgitster
authored andcommitted
stash: learn to parse -m/--message like commit does
`git stash push -m foo` uses "foo" as the message for the stash. But `git stash push -m"foo"` does not parse successfully. Similarly `git stash push --message="My stash message"` also fails. The stash documentation doesn't suggest this syntax should work, but gitcli does and my fingers have learned this pattern long ago for `commit`. Teach `git stash` to parse -mFoo and --message=Foo the same as `git commit` would do. Even though it's an internal function, add similar support to create_stash() for consistency. Signed-off-by: Phil Hord <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc849d8 commit 5675473

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

git-stash.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ create_stash () {
7676
shift
7777
stash_msg=${1?"BUG: create_stash () -m requires an argument"}
7878
;;
79+
-m*)
80+
stash_msg=${1#-m}
81+
;;
82+
--message=*)
83+
stash_msg=${1#--message=}
84+
;;
7985
-u|--include-untracked)
8086
shift
8187
untracked=${1?"BUG: create_stash () -u requires an argument"}
@@ -193,6 +199,12 @@ store_stash () {
193199
shift
194200
stash_msg="$1"
195201
;;
202+
-m*)
203+
stash_msg=${1#-m}
204+
;;
205+
--message=*)
206+
stash_msg=${1#--message=}
207+
;;
196208
-q|--quiet)
197209
quiet=t
198210
;;
@@ -251,6 +263,12 @@ push_stash () {
251263
test -z ${1+x} && usage
252264
stash_msg=$1
253265
;;
266+
-m*)
267+
stash_msg=${1#-m}
268+
;;
269+
--message=*)
270+
stash_msg=${1#--message=}
271+
;;
254272
--help)
255273
show_help
256274
;;

t/t3903-stash.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,99 @@ test_expect_success 'push -m shows right message' '
782782
test_cmp expect actual
783783
'
784784

785+
test_expect_success 'push -m also works without space' '
786+
>foo &&
787+
git add foo &&
788+
git stash push -m"unspaced test message" &&
789+
echo "stash@{0}: On master: unspaced test message" >expect &&
790+
git stash list -1 >actual &&
791+
test_cmp expect actual
792+
'
793+
794+
test_expect_success 'store -m foo shows right message' '
795+
git stash clear &&
796+
git reset --hard &&
797+
echo quux >bazzy &&
798+
git add bazzy &&
799+
STASH_ID=$(git stash create) &&
800+
git stash store -m "store m" $STASH_ID &&
801+
echo "stash@{0}: store m" >expect &&
802+
git stash list -1 >actual &&
803+
test_cmp expect actual
804+
'
805+
806+
test_expect_success 'store -mfoo shows right message' '
807+
git stash clear &&
808+
git reset --hard &&
809+
echo quux >bazzy &&
810+
git add bazzy &&
811+
STASH_ID=$(git stash create) &&
812+
git stash store -m"store mfoo" $STASH_ID &&
813+
echo "stash@{0}: store mfoo" >expect &&
814+
git stash list -1 >actual &&
815+
test_cmp expect actual
816+
'
817+
818+
test_expect_success 'store --message=foo shows right message' '
819+
git stash clear &&
820+
git reset --hard &&
821+
echo quux >bazzy &&
822+
git add bazzy &&
823+
STASH_ID=$(git stash create) &&
824+
git stash store --message="store message=foo" $STASH_ID &&
825+
echo "stash@{0}: store message=foo" >expect &&
826+
git stash list -1 >actual &&
827+
test_cmp expect actual
828+
'
829+
830+
test_expect_success 'store --message foo shows right message' '
831+
git stash clear &&
832+
git reset --hard &&
833+
echo quux >bazzy &&
834+
git add bazzy &&
835+
STASH_ID=$(git stash create) &&
836+
git stash store --message "store message foo" $STASH_ID &&
837+
echo "stash@{0}: store message foo" >expect &&
838+
git stash list -1 >actual &&
839+
test_cmp expect actual
840+
'
841+
842+
test_expect_success 'push -mfoo uses right message' '
843+
>foo &&
844+
git add foo &&
845+
git stash push -m"test mfoo" &&
846+
echo "stash@{0}: On master: test mfoo" >expect &&
847+
git stash list -1 >actual &&
848+
test_cmp expect actual
849+
'
850+
851+
test_expect_success 'push --message foo is synonym for -mfoo' '
852+
>foo &&
853+
git add foo &&
854+
git stash push --message "test message foo" &&
855+
echo "stash@{0}: On master: test message foo" >expect &&
856+
git stash list -1 >actual &&
857+
test_cmp expect actual
858+
'
859+
860+
test_expect_success 'push --message=foo is synonym for -mfoo' '
861+
>foo &&
862+
git add foo &&
863+
git stash push --message="test message=foo" &&
864+
echo "stash@{0}: On master: test message=foo" >expect &&
865+
git stash list -1 >actual &&
866+
test_cmp expect actual
867+
'
868+
869+
test_expect_success 'push -m shows right message' '
870+
>foo &&
871+
git add foo &&
872+
git stash push -m "test m foo" &&
873+
echo "stash@{0}: On master: test m foo" >expect &&
874+
git stash list -1 >actual &&
875+
test_cmp expect actual
876+
'
877+
785878
test_expect_success 'create stores correct message' '
786879
>foo &&
787880
git add foo &&

0 commit comments

Comments
 (0)