Skip to content

Commit 92e39e4

Browse files
jonseymourgitster
authored andcommitted
detached-stash: simplify stash_drop
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 064ed10 commit 92e39e4

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

git-stash.sh

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -424,35 +424,10 @@ apply_stash () {
424424
}
425425

426426
drop_stash () {
427-
have_stash || die 'No stash entries to drop'
427+
assert_stash_ref "$@"
428428

429-
while test $# != 0
430-
do
431-
case "$1" in
432-
-q|--quiet)
433-
GIT_QUIET=t
434-
;;
435-
*)
436-
break
437-
;;
438-
esac
439-
shift
440-
done
441-
442-
if test $# = 0
443-
then
444-
set x "$ref_stash@{0}"
445-
shift
446-
fi
447-
# Verify supplied argument looks like a stash entry
448-
s=$(git rev-parse --verify "$@") &&
449-
git rev-parse --verify "$s:" > /dev/null 2>&1 &&
450-
git rev-parse --verify "$s^1:" > /dev/null 2>&1 &&
451-
git rev-parse --verify "$s^2:" > /dev/null 2>&1 ||
452-
die "$*: not a valid stashed state"
453-
454-
git reflog delete --updateref --rewrite "$@" &&
455-
say "Dropped $* ($s)" || die "$*: Could not drop stash entry"
429+
git reflog delete --updateref --rewrite "${REV}" &&
430+
say "Dropped ${REV} ($s)" || die "${REV}: Could not drop stash entry"
456431

457432
# clear_stash if we just dropped the last stash entry
458433
git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash

0 commit comments

Comments
 (0)