diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 1b487f52fa..bf83e7ee29 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -590,8 +590,9 @@ class Tap end return unless remote - current_upstream_head = T.must(git_repository.origin_branch_name) - return if requested_remote.blank? && git_repository.origin_has_branch?(current_upstream_head) + current_upstream_head = git_repository.origin_branch_name + return if current_upstream_head.present? && requested_remote.blank? && + git_repository.origin_has_branch?(current_upstream_head) args = %w[fetch] args << "--quiet" if quiet @@ -600,6 +601,8 @@ class Tap safe_system "git", "-C", path, *args git_repository.set_head_origin_auto + current_upstream_head ||= T.must(git_repository.origin_branch_name) + new_upstream_head = T.must(git_repository.origin_branch_name) return if new_upstream_head == current_upstream_head