aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2015-09-11 11:00:07 +0100
committerMike McQuaid2015-09-11 11:00:27 +0100
commitb1ff9c42d67598d6d09a71ee4ef333847dd09e1b (patch)
treed251cb7f98eb97642a1f11f5310be59983b6a1a0 /Library
parent664e9e844a450d76051442c23261001b0a1acba6 (diff)
downloadbrew-b1ff9c42d67598d6d09a71ee4ef333847dd09e1b.tar.bz2
update: fix when `HEAD` doesn't exist.
e.g. when it's a detached `HEAD` through checking out a commit rather than a branch.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/update.rb10
-rw-r--r--Library/Homebrew/test/test_updater.rb2
2 files changed, 9 insertions, 3 deletions
diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb
index 4be763b6a..9890d15ef 100644
--- a/Library/Homebrew/cmd/update.rb
+++ b/Library/Homebrew/cmd/update.rb
@@ -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
diff --git a/Library/Homebrew/test/test_updater.rb b/Library/Homebrew/test/test_updater.rb
index 88f8c23aa..16f4f2e85 100644
--- a/Library/Homebrew/test/test_updater.rb
+++ b/Library/Homebrew/test/test_updater.rb
@@ -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")