[PATCH v5 0/6] stash: support pathspec argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Matthieu, Peff and Junio for the discussion on v3 and v4.

Changes since v4:
Dropped patch 1 from the series, as it's already in master

Instead of changing the external interface to git stash create, only
refactor the internal create_stash() function to take -m and -u
arguments.  This also simplifies the internal option parsing.

Make git stash -p an alias for git stash push -p, so git stash -p
<pathspec> is allowed.

Interdiff below:

diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index b0825f4aca..97194576ef 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -53,9 +53,8 @@ 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>] [--] [<pathspec>...]::
 
-	Save your local modifications to a new 'stash' and roll them
-	back to HEAD (in the working tree and in the index).
-	The <message> part is optional and gives
+	Save your local modifications to a new 'stash', and run `git reset
+	--hard` to revert them.  The <message> part is optional and gives
 	the description along with the stashed state.  For quickly making
 	a snapshot, you can omit _both_ "save" and <message>, but giving
 	only <message> does not trigger this action to prevent a misspelled
diff --git a/git-stash.sh b/git-stash.sh
index a184b1e274..1446fbe2e8 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -67,51 +67,20 @@ create_stash () {
 		case "$1" in
 		-m|--message)
 			shift
-			test -z ${1+x} && usage
-			stash_msg="$1"
-			new_style=t
+			stash_msg=${1-"BUG: create_stash () -m requires an argument"}
 			;;
 		-u|--include-untracked)
 			shift
-			test -z ${1+x} && usage
-			untracked="$1"
-			new_style=t
+			untracked=${1-"BUG: create_stash () -u requires an argument"}
 			;;
 		--)
 			shift
-			new_style=t
-			break
-			;;
-		*)
-			if test -n "$new_style"
-			then
-				echo "invalid argument"
-				option="$1"
-				# TRANSLATORS: $option is an invalid option, like
-				# `--blah-blah'. The 7 spaces at the beginning of the
-				# second line correspond to "error: ". So you should line
-				# up the second line with however many characters the
-				# translation of "error: " takes in your language. E.g. in
-				# English this is:
-				#
-				#    $ git stash save --blah-blah 2>&1 | head -n 2
-				#    error: unknown option for 'stash save': --blah-blah
-				#           To provide a message, use git stash save -- '--blah-blah'
-				eval_gettextln "error: unknown option for 'stash create': \$option"
-				usage
-			fi
 			break
 			;;
 		esac
 		shift
 	done
 
-	if test -z "$new_style"
-	then
-		stash_msg="$*"
-		set --
-	fi
-
 	git update-index -q --refresh
 	if no_changes "$@"
 	then
@@ -698,6 +667,8 @@ apply_to_branch () {
 	}
 }
 
+test "$1" = "-p" && set "push" "$@"
+
 PARSE_CACHE='--not-parsed'
 # The default command is "push" if nothing but options are given
 seen_non_option=
@@ -740,7 +711,7 @@ clear)
 	;;
 create)
 	shift
-	create_stash "$@" && echo "$w_commit"
+	create_stash -m "$*" && echo "$w_commit"
 	;;
 store)
 	shift
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 22ac75377b..c0ae41e724 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -800,15 +800,6 @@ test_expect_success 'create with multiple arguments for the message' '
 	test_cmp expect actual
 '
 
-test_expect_success 'new style stash create stores correct message' '
-	>foo &&
-	git add foo &&
-	STASH_ID=$(git stash create -m "create test message new style") &&
-	echo "On master: create test message new style" >expect &&
-	git show --pretty=%s -s ${STASH_ID} >actual &&
-	test_cmp expect actual
-'
-
 test_expect_success 'stash -- <filename> stashes and restores the file' '
 	>foo &&
 	>bar &&

Thomas Gummerer (6):
  stash: introduce push verb
  stash: add test for the create command line arguments
  stash: refactor stash_create
  stash: teach 'push' (and 'create_stash') to honor pathspec
  stash: use stash_push for no verb form
  stash: allow pathspecs in the no verb form

 Documentation/git-stash.txt        |  16 ++++-
 git-stash.sh                       | 128 ++++++++++++++++++++++++++++++-------
 t/t3903-stash.sh                   | 118 +++++++++++++++++++++++++++++++++-
 t/t3905-stash-include-untracked.sh |  26 ++++++++
 4 files changed, 261 insertions(+), 27 deletions(-)

-- 
2.11.0.301.g27b9849079.dirty




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]