From fa69b96be22369c3e07ee1302a078a3707e5469a Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 22 Jun 2026 16:45:32 +0900 Subject: [PATCH] Skip fetching bundled gems whose ref is already present With a warm gems/src cache the wanted tag or revision is already in the local clone, but the fetch ran unconditionally and added a github.com round-trip per gem that a transient outage could abort. Resolve the ref locally first and fetch only when it is missing. Co-Authored-By: Claude Opus 4.8 --- tool/fetch-bundled_gems.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tool/fetch-bundled_gems.rb b/tool/fetch-bundled_gems.rb index 4d2af06a850..67de8d538c3 100755 --- a/tool/fetch-bundled_gems.rb +++ b/tool/fetch-bundled_gems.rb @@ -28,7 +28,15 @@ unless File.exist?("#{n}/.git") system(*%W"git clone --depth=1 --no-tags #{u} #{n}") or abort end -c = (r ? [r] : ["v#{v}", v]).find do |c| +candidates = r ? [r] : ["v#{v}", v] + +# Skip fetching from the remote when the target ref already exists locally +# (e.g. restored from cache), so a transient network failure does not abort. +c = candidates.find do |c| + system("git", "rev-parse", "-q", "--verify", "#{c}^{commit}", out: File::NULL, err: File::NULL, chdir: n) +end + +c ||= candidates.find do |c| puts "fetching #{n} #{color.notice(c)} ..." system("git", "fetch", "origin", r || "refs/tags/#{c}:refs/tags/#{c}", chdir: n) end or abort