diff options
author | Thomas Marshall <[email protected]> | 2025-06-02 13:16:23 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-06-06 10:09:14 +0900 |
commit | ee55b82b34017051e6854a7940efc1615a693242 (patch) | |
tree | a827a67958cc8ce94d2e49e9a1e1b539b55b1e80 | |
parent | 6839eadd5312b7d2f15415a5f65677cb71d39a1c (diff) |
[rubygems/rubygems] Cache commit SHA ref revisions
If the `ref` option is a specific commit SHA, we can check to see if
it's already fetched locally. If it is, then we don't need to re-fetch
it from the remote.
The `ref` option might not be a commit SHA, so we're using the `#commit`
method which returns the full SHA if it's a commit ref, or the locked
revision, or nil.
This is a small improvement that will make `bundle update` slightly
faster in cases for git-sourced gems pinned to a specific commit.
https://github.com/rubygems/rubygems/commit/f434c2e66c
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 4 | ||||
-rw-r--r-- | spec/bundler/bundler/source/git/git_proxy_spec.rb | 19 |
2 files changed, 17 insertions, 6 deletions
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 8230584260..1a7a0959c9 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -305,8 +305,8 @@ module Bundler end def has_revision_cached? - return unless @revision && path.exist? - git("cat-file", "-e", @revision, dir: path) + return unless commit && path.exist? + git("cat-file", "-e", commit, dir: path) true rescue GitError false diff --git a/spec/bundler/bundler/source/git/git_proxy_spec.rb b/spec/bundler/bundler/source/git/git_proxy_spec.rb index aca4be1acd..492eee6444 100644 --- a/spec/bundler/bundler/source/git/git_proxy_spec.rb +++ b/spec/bundler/bundler/source/git/git_proxy_spec.rb @@ -305,10 +305,21 @@ RSpec.describe Bundler::Source::Git::GitProxy do context "with a commit ref" do let(:ref) { Digest::SHA1.hexdigest("ruby") } - it "fetches the specific revision" do - allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") - expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--depth", "1", "--", uri, "#{ref}:refs/#{ref}-sha"], path).and_return(["", "", clone_result]) - subject.checkout + context "when the revision exists locally" do + it "uses the cached revision" do + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") + expect(git_proxy).to receive(:git).with("cat-file", "-e", ref, dir: path).and_return(true) + subject.checkout + end + end + + context "when the revision doesn't exist locally" do + it "fetches the specific revision" do + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") + expect(git_proxy).to receive(:git).with("cat-file", "-e", ref, dir: path).and_raise(Bundler::GitError) + expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--depth", "1", "--", uri, "#{ref}:refs/#{ref}-sha"], path).and_return(["", "", clone_result]) + subject.checkout + end end end |