Skip to content

Commit

Permalink
git-stash.sh: don't default to refs/stash if invalid ref supplied
Browse files Browse the repository at this point in the history
apply_stash() and show_stash() each call rev-parse with
'--default refs/stash' as an argument. This option causes rev-parse to
operate on refs/stash if it is not able to successfully operate on any
element of the command line. This includes failure to supply a "valid"
revision. This has the effect of causing 'stash apply' and 'stash show'
to operate as if stash@{0} had been supplied when an invalid revision is
supplied.

e.g. 'git stash apply stash@{1}' would fall back to
     'git stash apply stash@{0}'

This patch modifies these two functions so that they avoid using the
--default option of rev-parse.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Brandon Casey authored and Shawn O. Pearce committed Sep 24, 2008
1 parent dc4179f commit da65e7c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions git-stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ show_stash () {
then
flags=--stat
fi
s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@")

if test $# = 0
then
set x "$ref_stash@{0}"
shift
fi

s=$(git rev-parse --revs-only --no-flags "$@")

w_commit=$(git rev-parse --verify "$s") &&
b_commit=$(git rev-parse --verify "$s^") &&
Expand All @@ -163,13 +170,19 @@ apply_stash () {
shift
esac

if test $# = 0
then
set x "$ref_stash@{0}"
shift
fi

# current index state
c_tree=$(git write-tree) ||
die 'Cannot apply a stash in the middle of a merge'

# stash records the work tree, and is a merge between the
# base commit (first parent) and the index tree (second parent).
s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@") &&
s=$(git rev-parse --revs-only --no-flags "$@") &&
w_tree=$(git rev-parse --verify "$s:") &&
b_tree=$(git rev-parse --verify "$s^1:") &&
i_tree=$(git rev-parse --verify "$s^2:") ||
Expand Down

0 comments on commit da65e7c

Please sign in to comment.