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

[PATCH v5 3/6] stash: refactor stash_create

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Feb 17, 2017, 22:41 UTC
Message-ID
<20170217224141.19183-4-t.gummerer@gmail.com>
In-Reply-To
<20170217224141.19183-1-t.gummerer@gmail.com>

Refactor the internal stash_create function to use a -m flag for specifying the message and -u flag to indicate whether untracked files should be added to the stash.

This makes it easier to pass a pathspec argument to stash_create in the next patch.

The user interface for git stash create stays the same.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 Documentation/git-stash.txt |  1 +
 git-stash.sh                | 23 +++++++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 2e9cef06e6..d93c47446a 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -17,6 +17,7 @@ SYNOPSIS
 	     [-u|--include-untracked] [-a|--all] [<message>]]
 'git stash' clear
 'git stash' create [<message>]
+'git stash' create [-m <message>] [-u|--include-untracked <untracked|all>]
 'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
 
 DESCRIPTION
diff --git a/git-stash.sh b/git-stash.sh
index 8365ebba2a..e76741d37d 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -58,8 +58,23 @@ clear_stash () {
 }
 
 create_stash () {
-	stash_msg="$1"
-	untracked="$2"
+	stash_msg=
+	untracked=
+	new_style=
+	while test $# != 0
+	do
+		case "$1" in
+		-m|--message)
+			shift
+			stash_msg=${1-"BUG: create_stash () -m requires an argument"}
+			;;
+		-u|--include-untracked)
+			shift
+			untracked=${1-"BUG: create_stash () -u requires an argument"}
+			;;
+		esac
+		shift
+	done
 
 	git update-index -q --refresh
 	if no_changes
@@ -268,7 +283,7 @@ push_stash () {
 	git reflog exists $ref_stash ||
 		clear_stash || die "$(gettext "Cannot initialize stash")"
 
-	create_stash "$stash_msg" $untracked
+	create_stash -m "$stash_msg" -u "$untracked"
 	store_stash -m "$stash_msg" -q $w_commit ||
 	die "$(gettext "Cannot save the current status")"
 	say "$(eval_gettext "Saved working directory and index state \$stash_msg")"
@@ -667,7 +682,7 @@ clear)
 	;;
 create)
 	shift
-	create_stash "$*" && echo "$w_commit"
+	create_stash -m "$*" && echo "$w_commit"
 	;;
 store)
 	shift
-- 
2.11.0.301.g27b9849079.dirty
Previous: Thomas GummererNext: Jeff King
Message 18 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.