From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
This patch introduces a common flags and revision parsing function to the following git stash commands:
* apply
* branch
* pop
* drop
* show
With these changes, git stash now:
* allows non-stash log entry references to passed to 'stash branch' provided they are stash-like
* relaxes the requirement that a stash log currently entry exists for 'stash show' or 'stash branch'
* does not attempt to drop the specified revision if it doesn't look like a stash log entry reference
* fails 'stash pop' and 'stash drop' early if the specified revision is not a stash log entry reference
* fails early if more than one stash-like commit is specified
* fails early if the specified revision is of the form ref@{n} and ref exists, but ref@{n} does not exist
* reports various error conditions that can occur across multiple commands with consistent error messages.
The implementation of several commands is simplified to a lesser or greater degree by taking
advantage of the new common parsing and validation function, parse_flags_and_rev().
This revision incorporates feedback and corrections from Johannes Sixt and Junio Hamano.
Version 5 differed from Version 4 by introducing a common parsing function and refactoring to
take advantage of that.
Version 6 differs from Version 5 by cleaning up and rationalising the new tests and splitting
out a commit (2/9) that is only required to work around an issue with git rev-parse.
2/9 of this series may be elided if this series is applied on top of the series:
"rev-parse: improve reporting of invalid log references"
Jon Seymour (9):
detached-stash: introduce parse_flags_and_revs function
detached-stash: work around git rev-parse failure to detect bad log refs
detached-stash: simplify stash_apply
detached-stash: simplify stash_drop
detached-stash: refactor git stash pop implementation
detached-stash: simplify git stash branch
detached-stash: simplify git stash show
detached-stash: tests of git stash with stash-like arguments
detached-stash: update Documentation
Documentation/git-stash.txt | 16 ++-
git-stash.sh | 223 ++++++++++++++++++++++++++++---------------
t/t3903-stash.sh | 112 ++++++++++++++++++++++
3 files changed, 268 insertions(+), 83 deletions(-)
--
1.7.2.1.110.g34f32
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
The implementation of stash_apply() is simplified to take
advantage of the common parsing function parse_flags_and_rev().
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 38 +++-----------------------------------
1 files changed, 3 insertions(+), 35 deletions(-)
@@ -358,40 +358,8 @@ assert_stash_ref() {} apply_stash(){-applied_stash=-unstash_index=-whiletest$#!=0-do-case"$1"in---index)-unstash_index=t-;;--q|--quiet)-GIT_QUIET=t-;;-*)-break-;;-esac-shift-done--iftest$#=0-then-have_stash||die'Nothing to apply'-applied_stash="$ref_stash@{0}"-else-applied_stash="$*"-fi--# stash records the work tree, and is a merge between the-# base commit (first parent) and the index tree (second parent).-s=$(gitrev-parse--quiet--verify--default$ref_stash"$@")&&-w_tree=$(gitrev-parse--quiet--verify"$s:")&&-b_tree=$(gitrev-parse--quiet--verify"$s^1:")&&-i_tree=$(gitrev-parse--quiet--verify"$s^2:")||-die"$*: no valid stashed state found"+assert_stash_like"$@"gitupdate-index-q--refresh&&gitdiff-files--quiet--ignore-submodules||
@@ -402,7 +370,7 @@ apply_stash () {die'Cannot apply a stash in the middle of a merge'unstashed_index_tree=-iftest-n"$unstash_index"&&test"$b_tree"!="$i_tree"&&+iftest-n"$INDEX_OPTION"&&test"$b_tree"!="$i_tree"&&test"$c_tree"!="$i_tree"thengitdiff-tree--binary$s^2^..$s^2|gitapply--cached
@@ -447,7 +415,7 @@ apply_stash () {else# Merge conflict; keep the exit status from merge-recursivestatus=$?-iftest-n"$unstash_index"+iftest-n"$INDEX_OPTION"thenecho>&2'Index was not unstashed.'fi
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
Introduce parse_flags_and_revs. This function requires that
there is at most one stash-like revision parameter and
zero or more flags.
It knows how to parse -q,--quiet and --index flags, but leaves
other flags parsed.
Specified revisions are checked to see that they are at
least stash-like (meaning: they look like something created
by git stash save or git stash create).
If this is so, then IS_STASH_LIKE is initialized to a non-empty value.
If the specified revision also looks like a stash log entry reference,
then IS_STASH_REF is initialized to a non-empty value.
References of the form ref@{spec} are required to precisely identify
an individual commit.
If no reference is specified, stash@{0} is assumed.
Once the specified reference is validated to be at least stash_like
an ensemble of derived variables, (w_commit, w_tree, b_commit, etc)
is initialized with a single call to git rev-parse.
Repeated calls to parse_flags_and_rev() avoid repeated calls
to git rev-parse if the specified arguments have already been
parsed.
Subsequent patches in the series modify the existing
git stash subcommands to make use of these functions
as appropriate.
An ensemble of supporting functions that make use of the state
established by parse_flags_and_rev(). These are described below:
The ancillary functions are:
is_stash_like(): which can be used to test
whether a specified commit looks like a commit created with
git stash save or git stash create.
assert_stash_like(): which can be used by
commands that misbehave unless their arguments stash-like.
is_stash_ref(): which checks whether an argument
is valid stash reference(e.g. is of the form
['refs/']stash['@{'something'}])
assert_stash_ref(): which can be used by commands
that misbehave unless their arguments are both stash-like and
refer to valid stash entries.
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
@@ -225,6 +225,128 @@ show_stash () {gitdiff$flags$b_commit$w_commit}+#+# Parses the remaining options looking for flags and+# at most one revision defaulting to ${ref_stash}@{0}+# if none found.+#+# Derives related tree and commit objects from the+# revision, if one is found.+#+# stash records the work tree, and is a merge between the+# base commit (first parent) and the index tree (second parent).+#+# REV is set to the symbolic version of the specified stash-like commit+# IS_STASH_LIKE is non-blank if ${REV} looks like a stash+# IS_STASH_REF is non-blank if the ${REV} looks like a stash ref+# s is set to the SHA1 of the stash commit+# w_commit is set to the commit containing the working tree+# b_commit is set to the base commit+# i_commit is set to the commit containing the index tree+# w_tree is set to the working tree+# b_tree is set to the base tree+# i_tree is set to the index tree+#+# GIT_QUIET is set to t if -q is specified+# INDEX_OPTION is set to --index if --index is specified.+# FLAGS is set to the remaining flags+#+# dies if:+# * too many revisions specified+# * no revision is specified and there is no stash stack+# * a revision is specified which cannot be resolve to a SHA1+# * a non-existent stash reference is specified+#++parse_flags_and_rev()+{+test"$PARSE_CACHE"="$*"&&return0# optimisation+PARSE_CACHE="$*"++IS_STASH_LIKE=+IS_STASH_REF=+INDEX_OPTION=+s=+w_commit=+b_commit=+i_commit=+w_tree=+b_tree=+i_tree=++REV=$(gitrev-parse--no-flags--symbolic"$@"2>/dev/null)+FLAGS=$(gitrev-parse--no-revs--"$@"2>/dev/null)++set--$FLAGS++FLAGS=+whiletest$#-ne0+do+case"$1"in+-q|--quiet)+GIT_QUIET=-t+;;+--index)+INDEX_OPTION=--index+;;+--)+:+;;+*)+FLAGS="${FLAGS}${FLAGS:+ }$1"+;;+esac+shift+done++set--$REV++case$#in+0)+have_stash||die"No stash found."+set--${ref_stash}@{0}+;;+1)+:+;;+*)+die"Too many revisions specified: $REV"+;;+esac++REV=$(gitrev-parse--quiet--symbolic--verify$12>/dev/null)||die"$1 is not valid reference"++i_commit=$(gitrev-parse--quiet--verify$REV^22>/dev/null)&&+set--$(gitrev-parse$REV$REV^1$REV:$REV^1:$REV^2:2>/dev/null)&&+s=$1&&+w_commit=$1&&+b_commit=$2&&+w_tree=$3&&+b_tree=$4&&+i_tree=$5&&+IS_STASH_LIKE=t&&+test"$ref_stash"="$(gitrev-parse--symbolic-full-name"${REV%@*}")"&&+IS_STASH_REF=t+++is_stash_like()+{+parse_flags_and_rev"$@"+test-n"$IS_STASH_LIKE"+}++assert_stash_like(){+is_stash_like"$@"||die"'$*' is not a stash-like commit"+}++is_stash_ref(){+is_stash_like"$@"&&test-n"$IS_STASH_REF"+}++assert_stash_ref(){+is_stash_ref"$@"||die"'$*' is not a stash reference"+}+ apply_stash(){applied_stash=unstash_index=
@@ -375,6 +497,7 @@ apply_to_branch () {drop_stash$stash}+PARSE_CACHE='--not-parsed'# The default command is "save" if nothing but options are givenseen_non_option=foropt
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
This commit is required because git rev-parse in 1.7.2 does not correctly
indicate invalid log references using a non-zero status code.
We use a proxy for the condition (non-empty error output) as
a substitute. This commit can be reverted when, and if, rev-parse
is fixed to indicate invalid log references with a status code.
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
@@ -328,6 +328,16 @@ parse_flags_and_rev()test"$ref_stash"="$(gitrev-parse--symbolic-full-name"${REV%@*}")"&&IS_STASH_REF=t+iftest"${REV}"!="${REV%{*\}}"+then+# maintainers: it would be better if git rev-parse indicated+# this condition with a non-zero status code but as of 1.7.2.1 it+# it did not. So, we use non-empty stderr output as a proxy for the+# condition of interest.+test-z"$(gitrev-parse"$REV"2>&1>/dev/null)"||die"$REV does not exist in the stash log"+fi++} is_stash_like(){
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
Previously, git stash drop would fail noisily while executing git reflog
delete if the specified revision was not a stash reference.
Now, git stash drop fails with an error message which more precisely
indicates the reason for failure.
Furthermore, git stash drop will now fail with a non-zero status code
if stash@{n} specifies a stash log entry that does not actually exist.
This change in behaviour is achieved by delegating argument parsing
to the common parse_flags_and_rev() function (via a call to
assert_stash_ref).
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 31 +++----------------------------
1 files changed, 3 insertions(+), 28 deletions(-)
@@ -424,35 +424,10 @@ apply_stash () {} drop_stash(){-have_stash||die'No stash entries to drop'+assert_stash_ref"$@"-whiletest$#!=0-do-case"$1"in--q|--quiet)-GIT_QUIET=t-;;-*)-break-;;-esac-shift-done--iftest$#=0-then-setx"$ref_stash@{0}"-shift-fi-# Verify supplied argument looks like a stash entry-s=$(gitrev-parse--verify"$@")&&-gitrev-parse--verify"$s:">/dev/null2>&1&&-gitrev-parse--verify"$s^1:">/dev/null2>&1&&-gitrev-parse--verify"$s^2:">/dev/null2>&1||-die"$*: not a valid stashed state"--gitreflogdelete--updateref--rewrite"$@"&&-say"Dropped $* ($s)"||die"$*: Could not drop stash entry"+gitreflogdelete--updateref--rewrite"${REV}"&&+say"Dropped ${REV} ($s)"||die"${REV}: Could not drop stash entry"# clear_stash if we just dropped the last stash entrygitrev-parse--verify"$ref_stash@{0}">/dev/null2>&1||clear_stash
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
Update the documentation to indicate that git stash branch only attempts
to drop the specified stash if it looks like stash reference.
Also changed the synopsis to more clearly indicate which commands require
a stash entry reference as opposed to merely a stash-like commit.
Signed-off-by: Jon Seymour <redacted>
---
Documentation/git-stash.txt | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
@@ -104,18 +104,22 @@ tree's changes, but also the index's ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally). +-When no `<stash>` is given, `stash@\{0}` is assumed.+When no `<stash>` is given, `stash@\{0}` is assumed, otherwise `<stash>` must+be a reference of the form `stash@\{<revision>}`. apply [--index] [-q|--quiet] [<stash>]::- Like `pop`, but do not remove the state from the stash list.+ Like `pop`, but do not remove the state from the stash list. Unlike `pop`,+ `<stash>` may be any commit that looks like a commit created by+ `stash save` or `stash create`. branch <branchname> [<stash>]:: Creates and checks out a new branch named `<branchname>` starting from the commit at which the `<stash>` was originally created, applies the- changes recorded in `<stash>` to the new working tree and index, then- drops the `<stash>` if that completes successfully. When no `<stash>`+ changes recorded in `<stash>` to the new working tree and index.+ If that succeeds, and `<stash>` is a reference of the form+ `stash@{<revision>}`, it then drops the `<stash>`. When no `<stash>` is given, applies the latest one. + This is useful if the branch on which you ran `git stash save` has
@@ -132,7 +136,9 @@ clear:: drop [-q|--quiet] [<stash>]:: Remove a single stashed state from the stash list. When no `<stash>`- is given, it removes the latest one. i.e. `stash@\{0}`+ is given, it removes the latest one. i.e. `stash@\{0}`, otherwise+ `<stash>` must a valid stash log reference of the form+ `stash@\{<revision>}`. create::
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
This commit refactors git stash show to make use of the assert_stash_like function.
git show now dies if the presented argument is non-stash-like.
Previous behaviour was to tolerate commits that were not even stash-like.
Previously, git stash show would accept stash-like arguments, but
only if there was a stash on the stack.
Now, git stash accepts stash-like arguments always and only fails
if no stash-like argument is specified and there is no stash stack.
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 14 ++------------
1 files changed, 2 insertions(+), 12 deletions(-)
@@ -210,19 +210,9 @@ list_stash () {} show_stash(){-have_stash||die'No stash found'--flags=$(gitrev-parse--no-revs--flags"$@")-iftest-z"$flags"-then-flags=--stat-fi--w_commit=$(gitrev-parse--quiet--verify--default$ref_stash"$@")&&-b_commit=$(gitrev-parse--quiet--verify"$w_commit^")||-die"'$*' is not a stash"+assert_stash_like"$@"-gitdiff$flags$b_commit$w_commit+gitdiff${FLAGS:---stat}$b_commit$w_commit}#
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
Adds new tests which check that:
* git stash branch handles a stash-like argument when there is a stash stack
* git stash branch handles a stash-like argument when there is not a stash stack
* git stash show handles a stash-like argument when there is a stash stack
* git stash show handles a stash-like argument when there is not a stash stack
* git stash drop fails early if the specified argument is not a stash reference
* git stash pop fails early if the specified argument is not a stash reference
* git stash * fails early if the reference supplied is bogus
* git stash fails early with stash@{n} where n >= length of stash log
| Amended per advice from Johannes Sixt to avoid burying stash create failures.
Signed-off-by: Jon Seymour <redacted>
---
t/t3903-stash.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 112 insertions(+), 0 deletions(-)
@@ -378,4 +378,116 @@ test_expect_failure 'stash file to directory' 'testfoo="$(catfile/file)"'+test_expect_success'stash branch - no stashes on stack, stash-like argument''+gitstashclear&&+test_when_finished"git reset --hard HEAD"&&+gitreset--hard&&+echofoo>>file&&+STASH_ID=$(gitstashcreate)&&+gitreset--hard&&+gitstashbranchstash-branch${STASH_ID}&&+test_when_finished"git reset --hard HEAD && git checkout master && git branch -D stash-branch"&&+test$(gitls-files--modified|wc-l)-eq1+'++test_expect_success'stash branch - stashes on stack, stash-like argument''+gitstashclear&&+test_when_finished"git reset --hard HEAD"&&+gitreset--hard&&+echofoo>>file&&+gitstash&&+test_when_finished"git stash drop"&&+echobar>>file&&+STASH_ID=$(gitstashcreate)&&+gitreset--hard&&+gitstashbranchstash-branch${STASH_ID}&&+test_when_finished"git reset --hard HEAD && git checkout master && git branch -D stash-branch"&&+test$(gitls-files--modified|wc-l)-eq1+'++test_expect_success'stash show - stashes on stack, stash-like argument''+gitstashclear&&+test_when_finished"git reset --hard HEAD"&&+gitreset--hard&&+echofoo>>file&&+gitstash&&+test_when_finished"git stash drop"&&+echobar>>file&&+STASH_ID=$(gitstashcreate)&&+gitreset--hard&&+gitstashshow${STASH_ID}+'+test_expect_success'stash show - no stashes on stack, stash-like argument''+gitstashclear&&+test_when_finished"git reset --hard HEAD"&&+gitreset--hard&&+echofoo>>file&&+STASH_ID=$(gitstashcreate)&&+gitreset--hard&&+gitstashshow${STASH_ID}+'++test_expect_success'stash drop - fail early if specified stash is not a stash reference''+gitstashclear&&+test_when_finished"git reset --hard HEAD && git stash clear"&&+gitreset--hard&&+echofoo>file&&+gitstash&&+echobar>file&&+gitstash&&+test_must_fail"git stash drop $(gitrev-parsestash@{0})"&&+gitstashpop&&+testbar="$(catfile)"&&+gitreset--hardHEAD+'++test_expect_success'stash pop - fail early if specified stash is not a stash reference''+gitstashclear&&+test_when_finished"git reset --hard HEAD && git stash clear"&&+gitreset--hard&&+echofoo>file&&+gitstash&&+echobar>file&&+gitstash&&+test_must_fail"git stash pop $(gitrev-parsestash@{0})"&&+gitstashpop&&+testbar="$(catfile)"&&+gitreset--hardHEAD+'++test_expect_success'ref with non-existant reflog''+gitstashclear&&+echobar5>file&&+echobar6>file2&&+gitaddfile2&&+gitstash&&+!"git rev-parse --quiet --verify does-not-exist"&&+test_must_fail"git stash drop does-not-exist"&&+test_must_fail"git stash drop does-not-exist@{0}"&&+test_must_fail"git stash pop does-not-exist"&&+test_must_fail"git stash pop does-not-exist@{0}"&&+test_must_fail"git stash apply does-not-exist"&&+test_must_fail"git stash apply does-not-exist@{0}"&&+test_must_fail"git stash show does-not-exist"&&+test_must_fail"git stash show does-not-exist@{0}"&&+test_must_fail"git stash branch tmp does-not-exist"&&+test_must_fail"git stash branch tmp does-not-exist@{0}"&&+gitstashdrop+'++test_expect_success'invalid ref of the form stash@{n}, n >= N''+gitstashclear&&+test_must_fail"git stash drop stash@{0}"&&+echobar5>file&&+echobar6>file2&&+gitaddfile2&&+gitstash&&+test_must_fail"git drop stash@{1}"&&+test_must_fail"git pop stash@{1}"&&+test_must_fail"git apply stash@{1}"&&+test_must_fail"git show stash@{1}"&&+test_must_fail"git branch tmp stash@{1}"&&+gitstashdrop+'+ test_done
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
git stash pop is abstracted into its own implementation function - pop_stash.
The behaviour is changed so that git stash pop fails early if the
the specified stash reference does not exist or does not refer to
an extant entry in the reflog of the reference stash.
This fixes the case where the apply succeeds, but the drop fails.
Previously this caused caused git stash pop to exit with a non-zero exit code
and a dirty tree.
Now, git stash pop fails with a non-zero exit code, but the working
tree is not modified.
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
This patch teaches git stash branch to tolerate stash-like arguments.
In particular, a stash is only required if an argument isn't specified
and the stash is only dropped if a stash entry reference was
specified or implied.
The implementation has been simplified by taking advantage of
assert_stash_like() and the variables established by
parse_flags_and_rev().
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 17 +++++++----------
1 files changed, 7 insertions(+), 10 deletions(-)
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
| amended to ensure trailing } is in 1/9
Introduce parse_flags_and_revs. This function requires that
there is at most one stash-like revision parameter and
zero or more flags.
It knows how to parse -q,--quiet and --index flags, but leaves
other flags parsed.
Specified revisions are checked to see that they are at
least stash-like (meaning: they look like something created
by git stash save or git stash create).
If this is so, then IS_STASH_LIKE is initialized to a non-empty value.
If the specified revision also looks like a stash log entry reference,
then IS_STASH_REF is initialized to a non-empty value.
References of the form ref@{spec} are required to precisely identify
an individual commit.
If no reference is specified, stash@{0} is assumed.
Once the specified reference is validated to be at least stash_like
an ensemble of derived variables, (w_commit, w_tree, b_commit, etc)
is initialized with a single call to git rev-parse.
Repeated calls to parse_flags_and_rev() avoid repeated calls
to git rev-parse if the specified arguments have already been
parsed.
Subsequent patches in the series modify the existing
git stash subcommands to make use of these functions
as appropriate.
An ensemble of supporting functions that make use of the state
established by parse_flags_and_rev(). These are described below:
The ancillary functions are:
is_stash_like(): which can be used to test
whether a specified commit looks like a commit created with
git stash save or git stash create.
assert_stash_like(): which can be used by
commands that misbehave unless their arguments stash-like.
is_stash_ref(): which checks whether an argument
is valid stash reference(e.g. is of the form
['refs/']stash['@{'something'}])
assert_stash_ref(): which can be used by commands
that misbehave unless their arguments are both stash-like and
refer to valid stash entries.
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 124 insertions(+), 0 deletions(-)
@@ -225,6 +225,129 @@ show_stash () {gitdiff$flags$b_commit$w_commit}+#+# Parses the remaining options looking for flags and+# at most one revision defaulting to ${ref_stash}@{0}+# if none found.+#+# Derives related tree and commit objects from the+# revision, if one is found.+#+# stash records the work tree, and is a merge between the+# base commit (first parent) and the index tree (second parent).+#+# REV is set to the symbolic version of the specified stash-like commit+# IS_STASH_LIKE is non-blank if ${REV} looks like a stash+# IS_STASH_REF is non-blank if the ${REV} looks like a stash ref+# s is set to the SHA1 of the stash commit+# w_commit is set to the commit containing the working tree+# b_commit is set to the base commit+# i_commit is set to the commit containing the index tree+# w_tree is set to the working tree+# b_tree is set to the base tree+# i_tree is set to the index tree+#+# GIT_QUIET is set to t if -q is specified+# INDEX_OPTION is set to --index if --index is specified.+# FLAGS is set to the remaining flags+#+# dies if:+# * too many revisions specified+# * no revision is specified and there is no stash stack+# * a revision is specified which cannot be resolve to a SHA1+# * a non-existent stash reference is specified+#++parse_flags_and_rev()+{+test"$PARSE_CACHE"="$*"&&return0# optimisation+PARSE_CACHE="$*"++IS_STASH_LIKE=+IS_STASH_REF=+INDEX_OPTION=+s=+w_commit=+b_commit=+i_commit=+w_tree=+b_tree=+i_tree=++REV=$(gitrev-parse--no-flags--symbolic"$@"2>/dev/null)+FLAGS=$(gitrev-parse--no-revs--"$@"2>/dev/null)++set--$FLAGS++FLAGS=+whiletest$#-ne0+do+case"$1"in+-q|--quiet)+GIT_QUIET=-t+;;+--index)+INDEX_OPTION=--index+;;+--)+:+;;+*)+FLAGS="${FLAGS}${FLAGS:+ }$1"+;;+esac+shift+done++set--$REV++case$#in+0)+have_stash||die"No stash found."+set--${ref_stash}@{0}+;;+1)+:+;;+*)+die"Too many revisions specified: $REV"+;;+esac++REV=$(gitrev-parse--quiet--symbolic--verify$12>/dev/null)||die"$1 is not valid reference"++i_commit=$(gitrev-parse--quiet--verify$REV^22>/dev/null)&&+set--$(gitrev-parse$REV$REV^1$REV:$REV^1:$REV^2:2>/dev/null)&&+s=$1&&+w_commit=$1&&+b_commit=$2&&+w_tree=$3&&+b_tree=$4&&+i_tree=$5&&+IS_STASH_LIKE=t&&+test"$ref_stash"="$(gitrev-parse--symbolic-full-name"${REV%@*}")"&&+IS_STASH_REF=t++}++is_stash_like()+{+parse_flags_and_rev"$@"+test-n"$IS_STASH_LIKE"+}++assert_stash_like(){+is_stash_like"$@"||die"'$*' is not a stash-like commit"+}++is_stash_ref(){+is_stash_like"$@"&&test-n"$IS_STASH_REF"+}++assert_stash_ref(){+is_stash_ref"$@"||die"'$*' is not a stash reference"+}+ apply_stash(){applied_stash=unstash_index=
@@ -375,6 +498,7 @@ apply_to_branch () {drop_stash$stash}+PARSE_CACHE='--not-parsed'# The default command is "save" if nothing but options are givenseen_non_option=foropt
From: Jon Seymour <hidden> Date: 2016-06-15 22:49:21
| amended to include trailing } in 1/9
This commit is required because git rev-parse in 1.7.2 does not correctly
indicate invalid log references using a non-zero status code.
We use a proxy for the condition (non-empty error output) as
a substitute. This commit can be reverted when, and if, rev-parse
is fixed to indicate invalid log references with a status code.
Signed-off-by: Jon Seymour <redacted>
---
git-stash.sh | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
@@ -328,6 +328,15 @@ parse_flags_and_rev()test"$ref_stash"="$(gitrev-parse--symbolic-full-name"${REV%@*}")"&&IS_STASH_REF=t+iftest"${REV}"!="${REV%{*\}}"+then+# maintainers: it would be better if git rev-parse indicated+# this condition with a non-zero status code but as of 1.7.2.1 it+# it did not. So, we use non-empty stderr output as a proxy for the+# condition of interest.+test-z"$(gitrev-parse"$REV"2>&1>/dev/null)"||die"$REV does not exist in the stash log"+fi+} is_stash_like()