@matheusbsbs / matheus-bagliano / commits / 92e39e4454
Fork 0

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 <jon.seymour@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jon Seymour committed Aug 21, 2010 at 14:08 UTC 92e39e44542b34923294fbb45069b8140d19976d
1 file changed +3 -28
git-stash.sh
+3 -28
@@ -424,35 +424,10 @@ apply_stash () {
424 }
425
426 drop_stash () {
427 - have_stash || die 'No stash entries to drop'
427 + assert_stash_ref "$@"
428
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"
431
432 # clear_stash if we just dropped the last stash entry
433 git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash