diff options
author | David RodrÃguez <[email protected]> | 2024-11-22 11:14:08 +0100 |
---|---|---|
committer | git <[email protected]> | 2024-11-29 15:27:39 +0000 |
commit | 9a4d91fa9507d981a02595d1760628f74396feec (patch) | |
tree | 6b181f43f42816b719d8f03b0fc1ed949f8df9d2 | |
parent | 2a8437a1eb54f8beedb9c1f2e2dd5001d04ca13b (diff) |
[rubygems/rubygems] Restore previous application cache format for git sources
And make sure `bundle install --local` can install from it without git.
https://github.com/rubygems/rubygems/commit/7d6b631620
-rw-r--r-- | lib/bundler/runtime.rb | 5 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 24 | ||||
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 6 | ||||
-rw-r--r-- | spec/bundler/cache/git_spec.rb | 5 |
4 files changed, 18 insertions, 22 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index dceb1b1c5a..cfad828e38 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -139,6 +139,11 @@ module Bundler spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache) end + Dir[cache_path.join("*/.git")].each do |git_dir| + FileUtils.rm_rf(git_dir) + FileUtils.touch(File.expand_path("../.bundlecache", git_dir)) + end + prune_cache(cache_path) unless Bundler.settings[:no_prune] end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 4245585fd7..b7870180f2 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -188,12 +188,10 @@ module Bundler end def specs(*) - set_up_app_cache!(app_cache_path) if use_app_cache? + 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_repository? - - fetch + fetch unless use_app_cache? checkout end @@ -225,9 +223,7 @@ module Bundler cached! FileUtils.rm_rf(app_cache_path) git_proxy.checkout if requires_checkout? - FileUtils.cp_r("#{cache_path}/.", app_cache_path) - FileUtils.touch(app_cache_path.join(".bundlecache")) - FileUtils.rm_rf(Dir.glob(app_cache_path.join("hooks/*.sample"))) + git_proxy.copy_to(app_cache_path, @submodules) end def load_spec_files @@ -273,7 +269,14 @@ module Bundler def checkout Bundler.ui.debug " * Checking out revision: #{ref}" - git_proxy.copy_to(install_path, submodules) + if use_app_cache? + SharedHelpers.filesystem_access(install_path.dirname) do |p| + FileUtils.mkdir_p(p) + end + FileUtils.cp_r("#{app_cache_path}/.", install_path) + else + git_proxy.copy_to(install_path, submodules) + end serialize_gemspecs_in(install_path) @copied = true end @@ -321,11 +324,6 @@ module Bundler @install_path = path end - def set_up_app_cache!(path) - FileUtils.mkdir_p(path.join("refs")) - set_cache_path!(path) - end - def has_app_cache? locked_revision && super end diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 744235bc04..a73e893829 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -84,12 +84,6 @@ module Bundler end end - def not_a_repository? - _, status = git_null("rev-parse", "--resolve-git-dir", path.to_s, dir: path) - - !status.success? - 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 ea91829003..c2e69cf3dc 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -27,7 +27,6 @@ RSpec.describe "bundle cache with git" do expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file - expect(Dir.glob(bundled_app("vendor/cache/foo-1.0-#{ref}/hooks/*.sample"))).to be_empty FileUtils.rm_rf lib_path("foo-1.0") expect(the_bundle).to include_gems "foo 1.0" @@ -240,7 +239,7 @@ RSpec.describe "bundle cache with git" do expect(the_bundle).to include_gem "foo 1.0" end - it "copies repository to vendor cache" do + it "copies repository to vendor cache, including submodules" do # CVE-2022-39253: https://lore.kernel.org/lkml/[email protected]/ system(*%W[git config --global protocol.file.allow always]) @@ -265,6 +264,7 @@ RSpec.describe "bundle cache with git" do bundle :cache expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist expect(the_bundle).to include_gems "has_submodule 1.0" end @@ -275,7 +275,6 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set path vendor/bundle" bundle "config set cache_all true" bundle :cache, "all-platforms" => true, :install => false |