summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2024-08-07 21:14:17 +0200
committergit <[email protected]>2024-08-21 12:06:28 +0000
commit54b6025887f46b5317c6917fe8c5d630013f923a (patch)
tree81dce9f8dbbc8970791fd5ab4992270386c44d11
parent7845ab1bc9e92fa8e5db06bea8928a4646a19976 (diff)
[rubygems/rubygems] Regeneration previous git application caches that didn't include bare repos
https://github.com/rubygems/rubygems/commit/417319ecb1
-rw-r--r--lib/bundler/source/git.rb8
-rw-r--r--lib/bundler/source/git/git_proxy.rb4
-rw-r--r--spec/bundler/cache/git_spec.rb40
3 files changed, 51 insertions, 1 deletions
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index 3f69ea1e65..9ce74adc2c 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -188,9 +188,11 @@ module Bundler
end
def specs(*)
- set_cache_path!(app_cache_path) if has_app_cache? && !local?
+ set_cache_path!(app_cache_path) if use_app_cache?
if requires_checkout? && !@copied
+ FileUtils.rm_rf(app_cache_path) if use_app_cache? && git_proxy.not_a_bare_repository?
+
fetch
checkout
end
@@ -321,6 +323,10 @@ module Bundler
cached_revision && super
end
+ def use_app_cache?
+ has_app_cache? && !local?
+ end
+
def requires_checkout?
allow_git_ops? && !local? && !cached_revision_checked_out?
end
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index 2fc9c6535f..d6ff7fb488 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -84,6 +84,10 @@ module Bundler
end
end
+ def not_a_bare_repository?
+ git_local("rev-parse", "--is-bare-repository", dir: path).strip == "false"
+ end
+
def contains?(commit)
allowed_with_path do
result, status = git_null("branch", "--contains", commit, dir: path)
diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb
index 4e3038f3ce..cbd755872c 100644
--- a/spec/bundler/cache/git_spec.rb
+++ b/spec/bundler/cache/git_spec.rb
@@ -258,6 +258,46 @@ RSpec.describe "bundle cache with git" do
end
end
+ it "can install after bundle cache generated with an older Bundler that kept checkouts in the cache" do
+ git = build_git("foo")
+ locked_revision = git.ref_for("main")
+ path_revision = git.ref_for("main", 11)
+
+ git_path = lib_path("foo-1.0")
+
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{git_path}'
+ G
+ lockfile <<~L
+ GIT
+ remote: #{git_path}/
+ revision: #{locked_revision}
+ specs:
+ foo (1.0)
+
+ GEM
+ remote: https://gem.repo1/
+ specs:
+
+ PLATFORMS
+ #{lockfile_platforms}
+
+ DEPENDENCIES
+ foo!
+
+ BUNDLED WITH
+ #{Bundler::VERSION}
+ L
+
+ # Simulate an old incorrect situation where vendor/cache would be the install location of git gems
+ FileUtils.mkdir_p bundled_app("vendor/cache")
+ FileUtils.cp_r git_path, bundled_app("vendor/cache/foo-1.0-#{path_revision}")
+ FileUtils.rm_rf bundled_app("vendor/cache/foo-1.0-#{path_revision}/.git")
+
+ bundle :install, env: { "BUNDLE_DEPLOYMENT" => "true", "BUNDLE_CACHE_ALL" => "true" }
+ end
+
it "respects the --no-install flag" do
git = build_git "foo", &:add_c_extension
ref = git.ref_for("main", 11)