git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v8 1/6] stash: introduce push verb

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Feb 28, 2017, 20:33 UTC
Message-ID
<20170228203340.18723-2-t.gummerer@gmail.com>
In-Reply-To
<20170228203340.18723-1-t.gummerer@gmail.com>

Introduce a new git stash push verb in addition to git stash save. The push verb is used to transition from the current command line arguments to a more conventional way, in which the message is given as an argument to the -m option.

This allows us to have pathspecs at the end of the command line arguments like other Git commands do, so that the user can say which subset of paths to stash (and leave others behind).

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 Documentation/git-stash.txt |  3 +++
 git-stash.sh                | 46 ++++++++++++++++++++++++++++++++++++++++++---
 t/t3903-stash.sh            |  9 +++++++++
 3 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 2e9e344cd7..d240df4af7 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -15,6 +15,8 @@ SYNOPSIS
 'git stash' branch <branchname> [<stash>]
 'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
 	     [-u|--include-untracked] [-a|--all] [<message>]]
+'git stash' push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
+	     [-u|--include-untracked] [-a|--all] [-m|--message <message>]]
 'git stash' clear
 'git stash' create [<message>]
 'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
@@ -46,6 +48,7 @@ OPTIONS
 -------
 
 save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]::
+push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>]::
 
 	Save your local modifications to a new 'stash' and roll them
 	back to HEAD (in the working tree and in the index).
diff --git a/git-stash.sh b/git-stash.sh
index 10c284d1aa..8365ebba2a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -9,6 +9,8 @@ USAGE="list [<options>]
    or: $dashless branch <branchname> [<stash>]
    or: $dashless [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
 		       [-u|--include-untracked] [-a|--all] [<message>]]
+   or: $dashless push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
+		      [-u|--include-untracked] [-a|--all] [-m <message>]
    or: $dashless clear"
 
 SUBDIRECTORY_OK=Yes
@@ -189,10 +191,11 @@ store_stash () {
 	return $ret
 }
 
-save_stash () {
+push_stash () {
 	keep_index=
 	patch_mode=
 	untracked=
+	stash_msg=
 	while test $# != 0
 	do
 		case "$1" in
@@ -216,6 +219,11 @@ save_stash () {
 		-a|--all)
 			untracked=all
 			;;
+		-m|--message)
+			shift
+			test -z ${1+x} && usage
+			stash_msg=$1
+			;;
 		--help)
 			show_help
 			;;
@@ -251,8 +259,6 @@ save_stash () {
 		die "$(gettext "Can't use --patch and --include-untracked or --all at the same time")"
 	fi
 
-	stash_msg="$*"
-
 	git update-index -q --refresh
 	if no_changes
 	then
@@ -291,6 +297,36 @@ save_stash () {
 	fi
 }
 
+save_stash () {
+	push_options=
+	while test $# != 0
+	do
+		case "$1" in
+		--)
+			shift
+			break
+			;;
+		-*)
+			# pass all options through to push_stash
+			push_options="$push_options $1"
+			;;
+		*)
+			break
+			;;
+		esac
+		shift
+	done
+
+	stash_msg="$*"
+
+	if test -z "$stash_msg"
+	then
+		push_stash $push_options
+	else
+		push_stash $push_options -m "$stash_msg"
+	fi
+}
+
 have_stash () {
 	git rev-parse --verify --quiet $ref_stash >/dev/null
 }
@@ -617,6 +653,10 @@ save)
 	shift
 	save_stash "$@"
 	;;
+push)
+	shift
+	push_stash "$@"
+	;;
 apply)
 	shift
 	apply_stash "$@"
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 2de3e18ce6..3577115807 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -775,4 +775,13 @@ test_expect_success 'stash is not confused by partial renames' '
 	test_path_is_missing file
 '
 
+test_expect_success 'push -m shows right message' '
+	>foo &&
+	git add foo &&
+	git stash push -m "test message" &&
+	echo "stash@{0}: On master: test message" >expect &&
+	git stash list -1 >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.12.0.428.g67fe103aa
Previous: Thomas GummererNext: Thomas Gummerer
Message 53 of 61 in “stash: support pathspec argument”
  1. 0/7 stash: support pathspec argumentThomas Gummerer, Feb 12, 2017
  2. 1/7 Documentation/stash: remove mention of git reset --hardThomas Gummerer, Feb 12, 2017
  3. 2/7 stash: introduce push verbThomas Gummerer, Feb 12, 2017
  4. 6/7 stash: use stash_push for no verb formThomas Gummerer, Feb 12, 2017
  5. 5/7 stash: teach 'push' (and 'create') to honor pathspecThomas Gummerer, Feb 12, 2017
  6. 4/7 stash: introduce new format createThomas Gummerer, Feb 12, 2017
  7. 3/7 stash: add test for the create command line argumentsThomas Gummerer, Feb 12, 2017
  8. 7/7 stash: allow pathspecs in the no verb formThomas Gummerer, Feb 12, 2017
  9. Thomas GummererFeb 12, 2017
  10. 0/6 stash: support pathspec argumentThomas Gummerer, Feb 17, 2017
  11. 2/6 stash: add test for the create command line argumentsThomas Gummerer, Feb 17, 2017
  12. 4/6 stash: teach 'push' (and 'create_stash') to honor pathspecThomas Gummerer, Feb 17, 2017
  13. 5/6 stash: use stash_push for no verb formThomas Gummerer, Feb 17, 2017
  14. 6/6 stash: allow pathspecs in the no verb formThomas Gummerer, Feb 17, 2017
  15. Jeff KingFeb 17, 2017
  16. Thomas GummererFeb 19, 2017
  17. 1/6 stash: introduce push verbThomas Gummerer, Feb 17, 2017
  18. 3/6 stash: refactor stash_createThomas Gummerer, Feb 17, 2017
  19. Jeff KingFeb 17, 2017
  20. Thomas GummererFeb 19, 2017
  21. Junio C HamanoFeb 17, 2017
  22. Thomas GummererFeb 17, 2017
  23. Junio C HamanoFeb 17, 2017
  24. 0/6 stash: support pathspec argumentThomas Gummerer, Feb 19, 2017
  25. 5/6 stash: use stash_push for no verb formThomas Gummerer, Feb 19, 2017
  26. 2/6 stash: add test for the create command line argumentsThomas Gummerer, Feb 19, 2017
  27. 3/6 stash: refactor stash_createThomas Gummerer, Feb 19, 2017
  28. 1/6 stash: introduce push verbThomas Gummerer, Feb 19, 2017
  29. 4/6 stash: teach 'push' (and 'create_stash') to honor pathspecThomas Gummerer, Feb 19, 2017
  30. Junio C HamanoFeb 21, 2017
  31. Thomas GummererFeb 25, 2017
  32. 6/6 stash: allow pathspecs in the no verb formThomas Gummerer, Feb 19, 2017
  33. Jeff KingFeb 20, 2017
  34. Junio C HamanoFeb 20, 2017
  35. Junio C HamanoFeb 20, 2017
  36. Thomas GummererFeb 25, 2017
  37. 0/6 stash: support pathspec argumentThomas Gummerer, Feb 25, 2017
  38. 2/6 stash: add test for the create command line argumentsThomas Gummerer, Feb 25, 2017
  39. 3/6 stash: refactor stash_createThomas Gummerer, Feb 25, 2017
  40. 6/6 stash: allow pathspecs in the no verb formThomas Gummerer, Feb 25, 2017
  41. 1/6 stash: introduce push verbThomas Gummerer, Feb 25, 2017
  42. 4/6 stash: teach 'push' (and 'create_stash') to honor pathspecThomas Gummerer, Feb 25, 2017
  43. Junio C HamanoFeb 27, 2017
  44. Thomas GummererFeb 27, 2017
  45. Junio C HamanoFeb 27, 2017
  46. Junio C HamanoFeb 27, 2017
  47. Junio C HamanoFeb 27, 2017
  48. Thomas GummererFeb 27, 2017
  49. 5/6 stash: use stash_push for no verb formThomas Gummerer, Feb 25, 2017
  50. 0/6 stash: support pathspec argumentThomas Gummerer, Feb 28, 2017
  51. 3/6 stash: refactor stash_createThomas Gummerer, Feb 28, 2017
  52. 6/6 stash: allow pathspecs in the no verb formThomas Gummerer, Feb 28, 2017
  53. 1/6 stash: introduce push verbThomas Gummerer, Feb 28, 2017
  54. 4/6 stash: teach 'push' (and 'create_stash') to honor pathspecThomas Gummerer, Feb 28, 2017
  55. Junio C HamanoFeb 28, 2017
  56. Thomas GummererMar 1, 2017
  57. Junio C HamanoMar 1, 2017
  58. 2/6 stash: add test for the create command line argumentsThomas Gummerer, Feb 28, 2017
  59. 5/6 stash: use stash_push for no verb formThomas Gummerer, Feb 28, 2017
  60. Thomas GummererFeb 14, 2017
  61. Thomas GummererFeb 17, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.