From 9e059952994a427916c665ccc78dc5b03938e6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 May 2025 14:54:57 +0000 Subject: [PATCH 1/5] move `git fetch` before getting `origin_branch_name` --- Library/Homebrew/tap.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 1b487f52fa..395fce2b59 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -590,14 +590,15 @@ 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) - args = %w[fetch] args << "--quiet" if quiet args << "origin" args << "+refs/heads/*:refs/remotes/origin/*" safe_system "git", "-C", path, *args + + current_upstream_head = T.must(git_repository.origin_branch_name) + return if requested_remote.blank? && git_repository.origin_has_branch?(current_upstream_head) + git_repository.set_head_origin_auto new_upstream_head = T.must(git_repository.origin_branch_name) From 24d9524bbdf65da3f53b132bcb9b1bc9c71ff62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 May 2025 16:01:35 +0000 Subject: [PATCH 2/5] remove `T.must` to avoid full fetch --- Library/Homebrew/tap.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 395fce2b59..3f0760e43f 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -590,17 +590,18 @@ class Tap end return unless remote + 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 args << "origin" args << "+refs/heads/*:refs/remotes/origin/*" safe_system "git", "-C", path, *args - - current_upstream_head = T.must(git_repository.origin_branch_name) - return if requested_remote.blank? && git_repository.origin_has_branch?(current_upstream_head) - git_repository.set_head_origin_auto + current_upstream_head = git_repository.origin_branch_name if current_upstream_head.nil? + new_upstream_head = T.must(git_repository.origin_branch_name) return if new_upstream_head == current_upstream_head From 0480411c6fbf858c704f94fc9ddaa5196ee6a40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 May 2025 16:35:50 +0000 Subject: [PATCH 3/5] use conditional assignment operator Co-authored-by: Bo Anderson --- Library/Homebrew/tap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 3f0760e43f..1e577fe688 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -600,7 +600,7 @@ class Tap safe_system "git", "-C", path, *args git_repository.set_head_origin_auto - current_upstream_head = git_repository.origin_branch_name if current_upstream_head.nil? + current_upstream_head ||= git_repository.origin_branch_name new_upstream_head = T.must(git_repository.origin_branch_name) return if new_upstream_head == current_upstream_head From 7476f09672ba150d22c2816aaee0590f31ac01b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 May 2025 16:43:54 +0000 Subject: [PATCH 4/5] format --- Library/Homebrew/tap.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 1e577fe688..ab1749bc2c 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -591,7 +591,8 @@ class Tap return unless remote 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) + return if current_upstream_head.present? && requested_remote.blank? && + git_repository.origin_has_branch?(current_upstream_head) args = %w[fetch] args << "--quiet" if quiet From 972414cec7a2b3fa8fe36df5bcafd621f8b076ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 27 May 2025 16:55:00 +0000 Subject: [PATCH 5/5] add a `T.must` after fetching tap --- Library/Homebrew/tap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index ab1749bc2c..bf83e7ee29 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -601,7 +601,7 @@ class Tap safe_system "git", "-C", path, *args git_repository.set_head_origin_auto - current_upstream_head ||= git_repository.origin_branch_name + 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