From 520b8496d45aed3974651fca8d8f644bae02c8ed Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Tue, 15 Sep 2015 22:08:55 -0700 Subject: [PATCH] Fix brew update for taps with non-master branches Fixes Homebrew/homebrew#43865. --- Library/Homebrew/cmd/update.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 9890d15ef1..bdee5b161f 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -187,6 +187,15 @@ class Updater @stashed = true end + # The upstream repository's default branch may not be master; + # check refs/remotes/origin/HEAD to see what the default + # origin branch name is, and use that. If not set, fall back to "master". + begin + @upstream_branch = `git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null` + @upstream_branch = @upstream_branch.chomp.sub('refs/remotes/origin/', '') + rescue ErrorDuringExecution + @upstream_branch = "master" + end begin @initial_branch = `git symbolic-ref --short HEAD 2>/dev/null`.chomp @@ -194,8 +203,8 @@ class Updater @initial_branch = "" end - if @initial_branch != "master" && !@initial_branch.empty? - safe_system "git", "checkout", "master", *quiet + if @initial_branch != @upstream_branch && !@initial_branch.empty? + safe_system "git", "checkout", @upstream_branch, *quiet end @initial_revision = read_current_revision @@ -208,8 +217,8 @@ class Updater args << ((ARGV.include? "--rebase") ? "--rebase" : "--no-rebase") args += quiet args << "origin" - # the refspec ensures that 'origin/master' gets updated - args << "refs/heads/master:refs/remotes/origin/master" + # the refspec ensures that the default upstream branch gets updated + args << "refs/heads/#{@upstream_branch}:refs/remotes/origin/#{@upstream_branch}" reset_on_interrupt { safe_system "git", *args }