Skip to content

Commit 8e10600

Browse files
authored
Merge pull request #6814 from rubygems/fix-git-cache
Fix `bundler/setup` unintendedly writing to the filesystem
2 parents fe5fd69 + 582eb2e commit 8e10600

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

bundler/lib/bundler/source/git.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,7 @@ def eql?(other)
6969

7070
def to_s
7171
begin
72-
at = if local?
73-
path
74-
elsif user_ref = options["ref"]
75-
if /\A[a-z0-9]{4,}\z/i.match?(ref)
76-
shortref_for_display(user_ref)
77-
else
78-
user_ref
79-
end
80-
elsif ref
81-
ref
82-
else
83-
current_branch
84-
end
72+
at = humanized_ref || current_branch
8573

8674
rev = "at #{at}@#{shortref_for_display(revision)}"
8775
rescue GitError
@@ -91,6 +79,10 @@ def to_s
9179
uri_with_specifiers([rev, glob_for_display])
9280
end
9381

82+
def identifier
83+
uri_with_specifiers([humanized_ref, cached_revision, glob_for_display])
84+
end
85+
9486
def uri_with_specifiers(specifiers)
9587
specifiers.compact!
9688

@@ -256,6 +248,20 @@ def local?
256248

257249
private
258250

251+
def humanized_ref
252+
if local?
253+
path
254+
elsif user_ref = options["ref"]
255+
if /\A[a-z0-9]{4,}\z/i.match?(ref)
256+
shortref_for_display(user_ref)
257+
else
258+
user_ref
259+
end
260+
elsif ref
261+
ref
262+
end
263+
end
264+
259265
def serialize_gemspecs_in(destination)
260266
destination = destination.expand_path(Bundler.root) if destination.relative?
261267
Dir["#{destination}/#{@glob}"].each do |spec_path|

bundler/spec/install/gemfile/git_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
expect(Dir["#{default_bundle_path}/cache/bundler/git/foo-1.0-*"]).to have_attributes :size => 1
3131
end
3232

33+
it "does not write to cache on bundler/setup" do
34+
cache_path = default_bundle_path.join("cache")
35+
FileUtils.rm_rf(cache_path)
36+
ruby "require 'bundler/setup'"
37+
expect(cache_path).not_to exist
38+
end
39+
3340
it "caches the git repo globally and properly uses the cached repo on the next invocation" do
3441
simulate_new_machine
3542
bundle "config set global_gem_cache true"

bundler/spec/install/git_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@
147147
#{Bundler::VERSION}
148148
L
149149

150-
original_lockfile = lockfile
151-
152150
# If GH#6743 is present, the first `bundle install` will change the
153151
# lockfile, by flipping the order (`other` would be moved to the top).
154152
#

0 commit comments

Comments
 (0)