update: restore previous state when interrupted

Fixes Homebrew/homebrew#19460.
Closes Homebrew/homebrew#22375.
This commit is contained in:
Jack Nagel 2013-09-10 15:08:03 -05:00
parent 15a3ae3d28
commit 4c55082e7c

View File

@ -86,11 +86,19 @@ class Updater
# the refspec ensures that 'origin/master' gets updated # the refspec ensures that 'origin/master' gets updated
args << "refs/heads/master:refs/remotes/origin/master" args << "refs/heads/master:refs/remotes/origin/master"
safe_system "git", *args reset_on_interrupt { safe_system "git", *args }
@current_revision = read_current_revision @current_revision = read_current_revision
end end
def reset_on_interrupt
ignore_interrupts { yield }
ensure
if $?.signaled? && $?.termsig == 2 # SIGINT
safe_system "git", "reset", "--hard", @initial_revision
end
end
# Matches raw git diff format (see `man git-diff-tree`) # Matches raw git diff format (see `man git-diff-tree`)
DIFFTREE_RX = /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} [0-9a-fA-F]{40} ([ACDMR])\d{0,3}\t(.+?)(?:\t(.+))?$/ DIFFTREE_RX = /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} [0-9a-fA-F]{40} ([ACDMR])\d{0,3}\t(.+?)(?:\t(.+))?$/