summaryrefslogtreecommitdiff
path: root/lib/bundler/source/git.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2023-07-11 20:33:33 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-07-13 11:36:03 +0900
commitc1fb25f6fc7427c25839493a6edd63199b794fdc (patch)
tree8ffa8b7c986cf13eaa3a1534756e83cca0b89d87 /lib/bundler/source/git.rb
parent8cf5297ba595af38a89ba8d2d428ae26b6bb00d2 (diff)
[rubygems/rubygems] Don't run any git commands when sorting and comparing git sources
Previously, when sorting and comparing git Gemfile vs lockfile sources during `bundler/setup` to figure out whether we need to re-resolve or not, we would try to find the default branch if nothing more specific was specified in the Gemfile. If the git cache has been deleted thought, that would fail. The error would still be swallowed (and the branch would simply not be displayed), but trying to clone would still generate the side effect of creating the parent folder for the clone. That could affect non-writable systems that don't expect `bundler/setup` to write to the filesystem at all. To fix this, override `Bundler::Source::Git#identifier` to use exclusively static information, so it does not even try to clone the repo nor generate any side effects. https://github.com/rubygems/rubygems/commit/582eb2ef39
Diffstat (limited to 'lib/bundler/source/git.rb')
-rw-r--r--lib/bundler/source/git.rb32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index f7ad6057b4..4a9f3731bd 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -69,19 +69,7 @@ module Bundler
def to_s
begin
- at = if local?
- path
- elsif user_ref = options["ref"]
- if /\A[a-z0-9]{4,}\z/i.match?(ref)
- shortref_for_display(user_ref)
- else
- user_ref
- end
- elsif ref
- ref
- else
- current_branch
- end
+ at = humanized_ref || current_branch
rev = "at #{at}@#{shortref_for_display(revision)}"
rescue GitError
@@ -91,6 +79,10 @@ module Bundler
uri_with_specifiers([rev, glob_for_display])
end
+ def identifier
+ uri_with_specifiers([humanized_ref, cached_revision, glob_for_display])
+ end
+
def uri_with_specifiers(specifiers)
specifiers.compact!
@@ -256,6 +248,20 @@ module Bundler
private
+ def humanized_ref
+ if local?
+ path
+ elsif user_ref = options["ref"]
+ if /\A[a-z0-9]{4,}\z/i.match?(ref)
+ shortref_for_display(user_ref)
+ else
+ user_ref
+ end
+ elsif ref
+ ref
+ end
+ end
+
def serialize_gemspecs_in(destination)
destination = destination.expand_path(Bundler.root) if destination.relative?
Dir["#{destination}/#{@glob}"].each do |spec_path|