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 <phil.hord@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phil Hord committed Nov 22, 2017 at 13:20 UTC 5675473fcbd18fb320ca17cffc107506f09c7464
2 files changed +111
git-stash.sh
+18
@@ -76,6 +76,12 @@ create_stash () {
76 shift
77 stash_msg=${1?"BUG: create_stash () -m requires an argument"}
78 ;;
79 + -m*)
80 + stash_msg=${1#-m}
81 + ;;
82 + --message=*)
83 + stash_msg=${1#--message=}
84 + ;;
85 -u|--include-untracked)
86 shift
87 untracked=${1?"BUG: create_stash () -u requires an argument"}
@@ -193,6 +199,12 @@ store_stash () {
199 shift
200 stash_msg="$1"
201 ;;
202 + -m*)
203 + stash_msg=${1#-m}
204 + ;;
205 + --message=*)
206 + stash_msg=${1#--message=}
207 + ;;
208 -q|--quiet)
209 quiet=t
210 ;;
@@ -251,6 +263,12 @@ push_stash () {
263 test -z ${1+x} && usage
264 stash_msg=$1
265 ;;
266 + -m*)
267 + stash_msg=${1#-m}
268 + ;;
269 + --message=*)
270 + stash_msg=${1#--message=}
271 + ;;
272 --help)
273 show_help
274 ;;
t/t3903-stash.sh
+93
@@ -782,6 +782,99 @@ test_expect_success 'push -m shows right message' '
782 test_cmp expect actual
783 '
784
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 +
878 test_expect_success 'create stores correct message' '
879 >foo &&
880 git add foo &&