Skip to contentSkip to conversation

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

PATCH Superseded Phil Hord 2 participants 3 messages Nov 21, 2017 – Nov 22, 2017 Documentation

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Hord

author
#0 lore raw

PATCH 1/1 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. 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.

---
 git-stash.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
git-stash.sh +18 -0
index 4b7495144..1114005ce 100755
@@ -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
 			;;
Signature · 1 line
2.15.0.471.g17a719cfe.dirty
author
#1 lore raw

PATCH 1/1 doc: prefer 'stash push' instead of 'stash save'

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

---
 Documentation/git-stash.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/git-stash.txt +2 -2
index 8be661007..056dfb866 100644
@@ -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
 ----------
Signature · 1 line
2.15.0.471.g17a719cfe.dirty
#2 lore raw
In reply to Phil Hord
Quoted 7 lines · Phil Hord

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.

Quoted 7 lines

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

---
 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.