[rubygems/rubygems] Regeneration previous git application caches that didn't include bare repos

https://github.com/rubygems/rubygems/commit/417319ecb1
This commit is contained in:
David Rodríguez 2024-08-07 21:14:17 +02:00 committed by git
parent 7845ab1bc9
commit 54b6025887
3 changed files with 51 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)