From a56c8f5aab5a6ffdd687de5134883df60cc4c919 Mon Sep 17 00:00:00 2001 From: Aaron M Watson Date: Mon, 24 Oct 2016 19:40:13 -0400 Subject: stash: allow stashes to be referenced by index only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of referencing "stash@{n}" explicitly, make it possible to simply reference as "n". Most users only reference stashes by their position in the stash stack (what I refer to as the "index" here). The syntax for the typical stash (stash@{n}) is slightly annoying and easy to forget, and sometimes difficult to escape properly in a script. Because of this the capability to do things with the stash by simply referencing the index is desirable. This patch includes the superior implementation provided by Ă˜sse Walle (thanks for that), with a slight change to fix a broken test in the test suite. I also merged the test scripts as suggested by Jeff King, and un-wrapped the documentation as suggested by Junio Hamano. Signed-off-by: Aaron M Watson Reviewed-by: Jeff King --- git-stash.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'git-stash.sh') diff --git a/git-stash.sh b/git-stash.sh index 90d63f293e..4546abaaef 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -384,9 +384,8 @@ parse_flags_and_rev() i_tree= u_tree= - REV=$(git rev-parse --no-flags --symbolic --sq "$@") || exit 1 - FLAGS= + REV= for opt do case "$opt" in @@ -404,6 +403,9 @@ parse_flags_and_rev() die "$(eval_gettext "unknown option: \$opt")" FLAGS="${FLAGS}${FLAGS:+ }$opt" ;; + *) + REV="${REV}${REV:+ }'$opt'" + ;; esac done @@ -422,6 +424,15 @@ parse_flags_and_rev() ;; esac + case "$1" in + *[!0-9]*) + : + ;; + *) + set -- "${ref_stash}@{$1}" + ;; + esac + REV=$(git rev-parse --symbolic --verify --quiet "$1") || { reference="$1" die "$(eval_gettext "\$reference is not a valid reference")" -- cgit v1.2.1