• Jeff King's avatar
    stash: fix accidental apply of non-existent stashes · 59d418fe
    Jeff King authored
    Once upon a time, "git rev-parse [email protected]{9999999}" did not
    generate an error. Therefore when we got an invalid stash
    reference in "stash apply", we could end up not noticing
    until quite late.  Commit b0f0ecd9 (detached-stash: work
    around git rev-parse failure to detect bad log refs,
    2010-08-21) handled this by checking for the "Log for stash
    has only %d entries" warning on stderr when we validated the
    ref.
    
    A few days later, e6eedc31 (rev-parse: exit with non-zero
    status if [email protected]{n} is not valid., 2010-08-24) fixed the
    original issue. That made the extra stderr test superfluous,
    but also introduced a new bug. Now the early call to:
    
      git rev-parse --symbolic "[email protected]"
    
    fails, but we don't notice the exit code. Worse, its empty
    output means we think the user didn't provide us a ref, and
    we try to apply [email protected]{0}.
    
    This patch checks the rev-parse exit code and fails early in
    the revision parsing process. We can also get rid of the
    stderr test; as a bonus, this means that "stash apply" can
    now run under GIT_TRACE=1 properly.
    Signed-off-by: default avatarJeff King <[email protected]>
    Acked-by: Jon Seymour's avatarJon Seymour <[email protected]>
    Signed-off-by: default avatarJunio C Hamano <[email protected]>
    59d418fe
git-stash.sh 9.88 KB