update: fix when HEAD doesn't exist.
e.g. when it's a detached `HEAD` through checking out a commit rather than a branch.
This commit is contained in:
parent
664e9e844a
commit
b1ff9c42d6
@ -187,7 +187,13 @@ class Updater
|
||||
@stashed = true
|
||||
end
|
||||
|
||||
@initial_branch = `git symbolic-ref --short HEAD`.chomp
|
||||
|
||||
begin
|
||||
@initial_branch = `git symbolic-ref --short HEAD 2>/dev/null`.chomp
|
||||
rescue ErrorDuringExecution
|
||||
@initial_branch = ""
|
||||
end
|
||||
|
||||
if @initial_branch != "master" && !@initial_branch.empty?
|
||||
safe_system "git", "checkout", "master", *quiet
|
||||
end
|
||||
@ -227,7 +233,7 @@ class Updater
|
||||
ignore_interrupts { yield }
|
||||
ensure
|
||||
if $?.signaled? && $?.termsig == 2 # SIGINT
|
||||
safe_system "git", "checkout", @initial_branch
|
||||
safe_system "git", "checkout", @initial_branch unless @initial_branch.empty?
|
||||
safe_system "git", "reset", "--hard", @initial_revision
|
||||
safe_system "git", "stash", "pop" if @stashed
|
||||
end
|
||||
|
||||
@ -58,7 +58,7 @@ class UpdaterTests < Homebrew::TestCase
|
||||
FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0"))
|
||||
@updater.diff = fixture(fixture_name)
|
||||
@updater.in_repo_expect("git diff --quiet", true)
|
||||
@updater.in_repo_expect("git symbolic-ref --short HEAD", "master")
|
||||
@updater.in_repo_expect("git symbolic-ref --short HEAD 2>/dev/null", "master")
|
||||
@updater.in_repo_expect("git rev-parse -q --verify HEAD", "1234abcd")
|
||||
@updater.in_repo_expect("git config core.autocrlf false")
|
||||
@updater.in_repo_expect("git pull --ff --no-rebase --quiet origin refs/heads/master:refs/remotes/origin/master")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user