summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-04-30 10:35:11 +0000
committerThe Bundler Bot <bot@bundler.io>2017-04-30 10:35:11 +0000
commit15bd319731e77a645a3e5c2a59c2fb274fcb12b7 (patch)
treef06517e05c3591c56fb5e86accdd91cabc384ee3
parentfea23637886c1b1bde471c98344b8844f82e60ce (diff)
parent7d8ae92f75fa262f466a3f0fca29e26f3af38f12 (diff)
downloadbundler-15bd319731e77a645a3e5c2a59c2fb274fcb12b7.tar.gz
Auto merge of #5624 - bundler:seg-fetch-named-symbolic-refs, r=indirect
[Git] Allow specifying non-branch symbolic refs > The intention here is to allow installing a gem from git using a > ref of the form "refs/zuul/" (which are used by the zuul > continuous-integration system). There are likely other use cases for > arbitrary refs. Closes #4845
-rw-r--r--.rubocop_todo.yml26
-rw-r--r--lib/bundler/source/git/git_proxy.rb19
-rw-r--r--spec/install/gemfile/git_spec.rb87
3 files changed, 109 insertions, 23 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 7d16768980..e9ec7c682b 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2017-04-08 17:26:10 -0500 using RuboCop version 0.48.0.
+# on 2017-04-28 14:46:27 +0200 using RuboCop version 0.48.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -72,12 +72,12 @@ Lint/UselessAssignment:
- 'lib/bundler/index.rb'
- 'lib/bundler/installer.rb'
-# Offense count: 451
+# Offense count: 456
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
- Max: 988
+ Max: 1048
-# Offense count: 2035
+# Offense count: 2083
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
@@ -87,7 +87,6 @@ Metrics/LineLength:
# Cop supports --auto-correct.
Performance/RedundantBlockCall:
Exclude:
- - 'lib/bundler/dsl.rb'
- 'lib/bundler/gem_helper.rb'
- 'lib/bundler/retry.rb'
- 'lib/bundler/shared_helpers.rb'
@@ -134,14 +133,13 @@ Style/AccessorMethodName:
Exclude:
- 'lib/bundler/source/git.rb'
-# Offense count: 4
+# Offense count: 3
Style/CaseEquality:
Exclude:
- - 'lib/bundler/dsl.rb'
- 'lib/bundler/match_platform.rb'
- 'lib/bundler/rubygems_ext.rb'
-# Offense count: 25
+# Offense count: 27
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
@@ -163,11 +161,11 @@ Style/ConditionalAssignment:
- 'lib/bundler/source/git.rb'
- 'lib/bundler/source/rubygems.rb'
-# Offense count: 158
+# Offense count: 161
Style/Documentation:
Enabled: false
-# Offense count: 304
+# Offense count: 308
# Cop supports --auto-correct.
Style/EmptyLineAfterMagicComment:
Enabled: false
@@ -205,7 +203,7 @@ Style/GlobalVars:
- 'lib/bundler/cli.rb'
- 'spec/spec_helper.rb'
-# Offense count: 17
+# Offense count: 16
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
@@ -215,7 +213,6 @@ Style/GuardClause:
- 'lib/bundler/cli/outdated.rb'
- 'lib/bundler/cli/package.rb'
- 'lib/bundler/definition.rb'
- - 'lib/bundler/dsl.rb'
- 'lib/bundler/installer.rb'
- 'lib/bundler/runtime.rb'
- 'lib/bundler/source/path/installer.rb'
@@ -240,7 +237,7 @@ Style/IfUnlessModifierOfIfUnless:
Style/IndentArray:
EnforcedStyle: consistent
-# Offense count: 34
+# Offense count: 35
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
@@ -361,12 +358,11 @@ Style/RaiseArgs:
- 'spec/bundler/rubygems_integration_spec.rb'
- 'spec/bundler/shared_helpers_spec.rb'
-# Offense count: 2
+# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantParentheses:
Exclude:
- 'lib/bundler/cli/console.rb'
- - 'lib/bundler/dsl.rb'
# Offense count: 1
# Cop supports --auto-correct.
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index e9b9c4dbe4..70b2d7e4f9 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -90,18 +90,21 @@ module Bundler
end
def checkout
- if path.exist?
- return if has_revision_cached?
- Bundler.ui.info "Fetching #{URICredentialsFilter.credential_filtered_uri(uri)}"
- in_path do
- git_retry %(fetch --force --quiet --tags #{uri_escaped_with_configured_credentials} "refs/heads/*:refs/heads/*")
- end
- else
- Bundler.ui.info "Fetching #{URICredentialsFilter.credential_filtered_uri(uri)}"
+ return if path.exist? && has_revision_cached?
+ extra_ref = "#{Shellwords.shellescape(ref)}:#{Shellwords.shellescape(ref)}" if ref && ref.start_with?("refs/")
+
+ Bundler.ui.info "Fetching #{URICredentialsFilter.credential_filtered_uri(uri)}"
+
+ unless path.exist?
SharedHelpers.filesystem_access(path.dirname) do |p|
FileUtils.mkdir_p(p)
end
git_retry %(clone #{uri_escaped_with_configured_credentials} "#{path}" --bare --no-hardlinks --quiet)
+ return unless extra_ref
+ end
+
+ in_path do
+ git_retry %(fetch --force --quiet --tags #{uri_escaped_with_configured_credentials} "refs/heads/*:refs/heads/*" #{extra_ref})
end
end
diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb
index 8843fb7ebb..a53d96582a 100644
--- a/spec/install/gemfile/git_spec.rb
+++ b/spec/install/gemfile/git_spec.rb
@@ -207,6 +207,93 @@ RSpec.describe "bundle install with git sources" do
expect(out).to eq("WIN")
end
+
+ it "works when the revision is a non-head ref" do
+ # want to ensure we don't fallback to master
+ update_git "foo", :path => lib_path("foo-1.0") do |s|
+ s.write("lib/foo.rb", "raise 'FAIL'")
+ end
+
+ Dir.chdir(lib_path("foo-1.0")) do
+ `git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1`
+ end
+
+ # want to ensure we don't fallback to HEAD
+ update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s|
+ s.write("lib/foo.rb", "raise 'FAIL'")
+ end
+
+ install_gemfile! <<-G
+ git "#{lib_path("foo-1.0")}", :ref => "refs/bundler/1" do
+ gem "foo"
+ end
+ G
+ expect(err).to lack_errors
+
+ run! <<-RUBY
+ require 'foo'
+ puts "WIN" if defined?(FOO)
+ RUBY
+
+ expect(out).to eq("WIN")
+ end
+
+ it "works when the revision is a non-head ref and it was previously downloaded" do
+ install_gemfile! <<-G
+ git "#{lib_path("foo-1.0")}" do
+ gem "foo"
+ end
+ G
+
+ # want to ensure we don't fallback to master
+ update_git "foo", :path => lib_path("foo-1.0") do |s|
+ s.write("lib/foo.rb", "raise 'FAIL'")
+ end
+
+ Dir.chdir(lib_path("foo-1.0")) do
+ `git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1`
+ end
+
+ # want to ensure we don't fallback to HEAD
+ update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s|
+ s.write("lib/foo.rb", "raise 'FAIL'")
+ end
+
+ install_gemfile! <<-G
+ git "#{lib_path("foo-1.0")}", :ref => "refs/bundler/1" do
+ gem "foo"
+ end
+ G
+ expect(err).to lack_errors
+
+ run! <<-RUBY
+ require 'foo'
+ puts "WIN" if defined?(FOO)
+ RUBY
+
+ expect(out).to eq("WIN")
+ end
+
+ it "does not download random non-head refs" do
+ Dir.chdir(lib_path("foo-1.0")) do
+ `git update-ref -m 'Bundler Spec!' refs/bundler/1 master~1`
+ end
+
+ install_gemfile! <<-G
+ git "#{lib_path("foo-1.0")}" do
+ gem "foo"
+ end
+ G
+
+ # ensure we also git fetch after cloning
+ bundle! :update
+
+ Dir.chdir(Dir[system_gem_path("cache/bundler/git/foo-*")].first) do
+ @out = sys_exec("git ls-remote .")
+ end
+
+ expect(out).not_to include("refs/bundler/1")
+ end
end
describe "when specifying a branch" do