Skip to content

Commit da65e7c

Browse files
drafnelspearce
authored andcommitted
git-stash.sh: don't default to refs/stash if invalid ref supplied
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>
1 parent dc4179f commit da65e7c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

git-stash.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@ show_stash () {
144144
then
145145
flags=--stat
146146
fi
147-
s=$(git rev-parse --revs-only --no-flags --default $ref_stash "$@")
147+
148+
if test $# = 0
149+
then
150+
set x "$ref_stash@{0}"
151+
shift
152+
fi
153+
154+
s=$(git rev-parse --revs-only --no-flags "$@")
148155

149156
w_commit=$(git rev-parse --verify "$s") &&
150157
b_commit=$(git rev-parse --verify "$s^") &&
@@ -163,13 +170,19 @@ apply_stash () {
163170
shift
164171
esac
165172

173+
if test $# = 0
174+
then
175+
set x "$ref_stash@{0}"
176+
shift
177+
fi
178+
166179
# current index state
167180
c_tree=$(git write-tree) ||
168181
die 'Cannot apply a stash in the middle of a merge'
169182

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

0 commit comments

Comments
 (0)