aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
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/Homebrew/cmd
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/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/update.rb10
1 files changed, 8 insertions, 2 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