Skip to content

Commit 9a4d91f

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] Restore previous application cache format for git sources
And make sure `bundle install --local` can install from it without git. rubygems/rubygems@7d6b631620
1 parent 2a8437a commit 9a4d91f

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

lib/bundler/runtime.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def cache(custom_path = nil, local = false)
139139
spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
140140
end
141141

142+
Dir[cache_path.join("*/.git")].each do |git_dir|
143+
FileUtils.rm_rf(git_dir)
144+
FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
145+
end
146+
142147
prune_cache(cache_path) unless Bundler.settings[:no_prune]
143148
end
144149

lib/bundler/source/git.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,10 @@ def local_override!(path)
188188
end
189189

190190
def specs(*)
191-
set_up_app_cache!(app_cache_path) if use_app_cache?
191+
set_cache_path!(app_cache_path) if use_app_cache?
192192

193193
if requires_checkout? && !@copied
194-
FileUtils.rm_rf(app_cache_path) if use_app_cache? && git_proxy.not_a_repository?
195-
196-
fetch
194+
fetch unless use_app_cache?
197195
checkout
198196
end
199197

@@ -225,9 +223,7 @@ def cache(spec, custom_path = nil)
225223
cached!
226224
FileUtils.rm_rf(app_cache_path)
227225
git_proxy.checkout if requires_checkout?
228-
FileUtils.cp_r("#{cache_path}/.", app_cache_path)
229-
FileUtils.touch(app_cache_path.join(".bundlecache"))
230-
FileUtils.rm_rf(Dir.glob(app_cache_path.join("hooks/*.sample")))
226+
git_proxy.copy_to(app_cache_path, @submodules)
231227
end
232228

233229
def load_spec_files
@@ -273,7 +269,14 @@ def local?
273269

274270
def checkout
275271
Bundler.ui.debug " * Checking out revision: #{ref}"
276-
git_proxy.copy_to(install_path, submodules)
272+
if use_app_cache?
273+
SharedHelpers.filesystem_access(install_path.dirname) do |p|
274+
FileUtils.mkdir_p(p)
275+
end
276+
FileUtils.cp_r("#{app_cache_path}/.", install_path)
277+
else
278+
git_proxy.copy_to(install_path, submodules)
279+
end
277280
serialize_gemspecs_in(install_path)
278281
@copied = true
279282
end
@@ -321,11 +324,6 @@ def set_install_path!(path)
321324
@install_path = path
322325
end
323326

324-
def set_up_app_cache!(path)
325-
FileUtils.mkdir_p(path.join("refs"))
326-
set_cache_path!(path)
327-
end
328-
329327
def has_app_cache?
330328
locked_revision && super
331329
end

lib/bundler/source/git/git_proxy.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ def current_branch
8484
end
8585
end
8686

87-
def not_a_repository?
88-
_, status = git_null("rev-parse", "--resolve-git-dir", path.to_s, dir: path)
89-
90-
!status.success?
91-
end
92-
9387
def contains?(commit)
9488
allowed_with_path do
9589
result, status = git_null("branch", "--contains", commit, dir: path)

spec/bundler/cache/git_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist
2828
expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist
2929
expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file
30-
expect(Dir.glob(bundled_app("vendor/cache/foo-1.0-#{ref}/hooks/*.sample"))).to be_empty
3130

3231
FileUtils.rm_rf lib_path("foo-1.0")
3332
expect(the_bundle).to include_gems "foo 1.0"
@@ -240,7 +239,7 @@
240239
expect(the_bundle).to include_gem "foo 1.0"
241240
end
242241

243-
it "copies repository to vendor cache" do
242+
it "copies repository to vendor cache, including submodules" do
244243
# CVE-2022-39253: https://lore.kernel.org/lkml/[email protected]/
245244
system(*%W[git config --global protocol.file.allow always])
246245

@@ -265,6 +264,7 @@
265264
bundle :cache
266265

267266
expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist
267+
expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist
268268
expect(the_bundle).to include_gems "has_submodule 1.0"
269269
end
270270

@@ -275,7 +275,6 @@
275275
source "https://gem.repo1"
276276
gem "foo", :git => '#{lib_path("foo-1.0")}'
277277
G
278-
bundle "config set path vendor/bundle"
279278
bundle "config set cache_all true"
280279
bundle :cache, "all-platforms" => true, :install => false
281280

0 commit comments

Comments
 (0)