Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5624 - bundler:seg-fetch-named-symbolic-refs, r=indirect
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bundlerbot committed Apr 30, 2017
2 parents fea2363 + 7d8ae92 commit 15bd319
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 23 deletions.
26 changes: 11 additions & 15 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 11 additions & 8 deletions lib/bundler/source/git/git_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ def full_version
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

Expand Down
87 changes: 87 additions & 0 deletions spec/install/gemfile/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,93 @@

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
Expand Down

0 comments on commit 15bd319

Please sign in to comment.