threads / patch / 47289

patchstash: Learn to parse -m/--message like commit does

Subject: [PATCH] stash: Learn to parse -m/--message like commit does

## tl;dr

3 messages between Nov 21, 2017 and Nov 22, 2017. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Phil Hord· Nov 21, 2017, 23:26 UTC · lore

`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. Nothing in the documentation suggests this syntax should work, but it does work for `git commit`, and my fingers have learned this pattern long ago.

Teach `git stash` to parse -mFoo and --message=Foo the same as `git commit` would do.

Signed-off-by: Phil Hord <phil.hord@gmail.com>
---
 git-stash.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Show changes to git-stash.sh +18 −0
diff --git a/git-stash.sh b/git-stash.sh
index 4b7495144..1114005ce 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -76,6 +76,12 @@ create_stash () {
 			shift
 			stash_msg=${1?"BUG: create_stash () -m requires an argument"}
 			;;
+		-m*)
+			stash_msg=${1#-m}
+			;;
+		--message=*)
+			stash_msg=${1#--message=}
+			;;
 		-u|--include-untracked)
 			shift
 			untracked=${1?"BUG: create_stash () -u requires an argument"}
@@ -193,6 +199,12 @@ store_stash () {
 			shift
 			stash_msg="$1"
 			;;
+		-m*)
+			stash_msg=${1#-m}
+			;;
+		--message=*)
+			stash_msg=${1#--message=}
+			;;
 		-q|--quiet)
 			quiet=t
 			;;
@@ -251,6 +263,12 @@ push_stash () {
 			test -z ${1+x} && usage
 			stash_msg=$1
 			;;
+		-m*)
+			stash_msg=${1#-m}
+			;;
+		--message=*)
+			stash_msg=${1#--message=}
+			;;
 		--help)
 			show_help
 			;;
-- 
2.15.0.471.g17a719cfe.dirty
Phil Hord· Nov 21, 2017, 23:26 UTC · re: Phil Hord · lore

[PATCH] doc: prefer 'stash push' instead of 'stash save'

Although `git stash save` was deprecated recently, some parts of the documentation still refer to it.

Signed-off-by: Phil Hord <phil.hord@gmail.com>
---
 Documentation/git-stash.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to Documentation/git-stash.txt +2 −2
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 8be661007..056dfb866 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -175,14 +175,14 @@ create::
 	return its object name, without storing it anywhere in the ref
 	namespace.
 	This is intended to be useful for scripts.  It is probably not
-	the command you want to use; see "save" above.
+	the command you want to use; see "push" above.
 
 store::
 
 	Store a given stash created via 'git stash create' (which is a
 	dangling merge commit) in the stash ref, updating the stash
 	reflog.  This is intended to be useful for scripts.  It is
-	probably not the command you want to use; see "save" above.
+	probably not the command you want to use; see "push" above.
 
 DISCUSSION
 ----------
-- 
2.15.0.471.g17a719cfe.dirty
Junio C Hamano· Nov 22, 2017, 04:44 UTC · re: Phil Hord · lore

Re: [PATCH] stash: Learn to parse -m/--message like commit does

Phil Hord <phil.hord@gmail.com> writes:
Show 14 quoted lines
> `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.  Nothing
> in the documentation suggests this syntax should work, but it does
> work for `git commit`, and my fingers have learned this pattern long
> ago.
>
> Teach `git stash` to parse -mFoo and --message=Foo the same as
> `git commit` would do.
>
> Signed-off-by: Phil Hord <phil.hord@gmail.com>
> ---
>  git-stash.sh | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
Makes sense.  Thanks.

I wonder if you want to add a trivial test or two for this, if "git stash [save|push|nothing] -m foo" is already tested. It appears that t3903 already has a test that does 'push -m "test message"' and sees if that appears in the output of "list", which looks like the ideal place to do so.

← back to recent threads