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

bundle config --local gemfile /foo/bar/MyGemfile now works #3320

Merged
merged 1 commit into from
Jan 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/bundler.rb
Expand Up @@ -193,7 +193,13 @@ def cache
end

def root
@root ||= default_gemfile.dirname.expand_path
@root ||= begin
default_gemfile.dirname.expand_path
rescue GemfileNotFound
bundle_dir = default_bundle_dir
raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir
Pathname.new(File.expand_path("..", bundle_dir))
end
end

def app_config_path
Expand Down Expand Up @@ -221,7 +227,7 @@ def settings
return @settings if defined?(@settings)
@settings = Settings.new(app_config_path)
rescue GemfileNotFound
@settings = Settings.new
@settings = Settings.new(Pathname.new(".bundle").expand_path)
end

def with_original_env
Expand Down Expand Up @@ -260,6 +266,10 @@ def default_lockfile
SharedHelpers.default_lockfile
end

def default_bundle_dir
SharedHelpers.default_bundle_dir
end

def system_bindir
# Gem.bindir doesn't always return the location that Rubygems will install
# system binaries. If you put '-n foo' in your .gemrc, Rubygems will
Expand Down
3 changes: 2 additions & 1 deletion lib/bundler/cli.rb
Expand Up @@ -18,7 +18,8 @@ def self.start(*)
def initialize(*args)
super
current_cmd = args.last[:current_command].name
ENV['BUNDLE_GEMFILE'] = File.expand_path(options[:gemfile]) if options[:gemfile]
custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
ENV['BUNDLE_GEMFILE'] = File.expand_path(custom_gemfile) if custom_gemfile
Bundler::Retry.attempts = options[:retry] || Bundler.settings[:retry] || Bundler::Retry::DEFAULT_ATTEMPTS
Bundler.rubygems.ui = UI::RGProxy.new(Bundler.ui)
auto_install if AUTO_INSTALL_CMDS.include?(current_cmd)
Expand Down
29 changes: 24 additions & 5 deletions lib/bundler/shared_helpers.rb
Expand Up @@ -36,6 +36,11 @@ def default_lockfile
end
end

def default_bundle_dir
bundle_dir = find_directory(".bundle")
Pathname.new(bundle_dir) if bundle_dir
end

def in_bundle?
find_gemfile
end
Expand Down Expand Up @@ -75,6 +80,22 @@ def find_gemfile
given = ENV['BUNDLE_GEMFILE']
return given if given && !given.empty?

find_file('Gemfile', 'gems.rb')
end

def find_file(*names)
search_up(*names) {|filename|
return filename if File.file?(filename)
}
end

def find_directory(*names)
search_up(*names) {|dirname|
return dirname if File.directory?(dirname)
}
end

def search_up(*names)
previous = nil
current = File.expand_path(SharedHelpers.pwd)

Expand All @@ -84,12 +105,10 @@ def find_gemfile
return nil if File.file?(File.join(current, 'bundler.gemspec'))
end

# otherwise return the Gemfile if it's there
['Gemfile', 'gems.rb'].each do |file|
path = File.join(current, file)
return path if File.file?(path)
names.each do |name|
filename = File.join(current, name)
yield filename
end

current, previous = File.expand_path("..", current), current
end
end
Expand Down
18 changes: 6 additions & 12 deletions man/bundle-config.ronn
Expand Up @@ -90,6 +90,12 @@ learn more about their operation in [bundle install(1)][bundle-install].
* `bin` (`BUNDLE_BIN`):
Install executables from gems in the bundle to the specified directory.
Defaults to `false`.
* `gemfile` (`BUNDLE_GEMFILE`):
The name of the file that bundler should use as the `Gemfile`. This location
of this file also sets the root of the project, which is used to resolve
relative paths in the `Gemfile`, among other things. By default, bundler
will search up from the current working directory until it finds a
`Gemfile`.
* `ssl_ca_cert` (`BUNDLE_SSL_CA_CERT`):
Path to a designated CA certificate file or folder containing multiple
certificates for trusted CAs in PEM format.
Expand All @@ -104,18 +110,6 @@ You can set them globally either via environment variables or `bundle config`,
whichever is preferable for your setup. If you use both, environment variables
will take preference over global settings.

An additional setting is available only as an environment variable:

* `BUNDLE_GEMFILE`:
The name of the file that bundler should use as the `Gemfile`. This location
of this file also sets the root of the project, which is used to resolve
relative paths in the `Gemfile`, among other things. By default, bundler
will search up from the current working directory until it finds a
`Gemfile`.

Bundler will ignore any `BUNDLE_GEMFILE` entries in local or global
configuration files.

## LOCAL GIT REPOS

Bundler also allows you to work against a git repository locally
Expand Down
18 changes: 18 additions & 0 deletions spec/commands/config_spec.rb
Expand Up @@ -244,5 +244,23 @@
expect(out).to match(long_string)
end
end
end

describe "setting gemfile via config" do
context "when only the non-default Gemfile exists" do
before do
gemfile bundled_app("NotGemfile"), <<-G
source "file://#{gem_repo1}"
gem 'rack'
G
end
it "persists the gemfile location to .bundle/config" do

bundle "config --local gemfile #{bundled_app("NotGemfile")}"
expect(File.exists?(".bundle/config")).to eq(true)

bundle "config"
expect(out).to include("NotGemfile")
end
end
end
26 changes: 26 additions & 0 deletions spec/install/gemfile_spec.rb
Expand Up @@ -26,6 +26,32 @@
end
end

context "with gemfile set via config" do
before do
gemfile bundled_app("NotGemfile"), <<-G
source "file://#{gem_repo1}"
gem 'rack'
G

bundle "config --local gemfile #{bundled_app("NotGemfile")}"
end
it "uses the gemfile to install" do
bundle "install"
bundle "show"

expect(out).to include("rack (1.0.0)")
end
it "uses the gemfile while in a subdirectory" do
bundled_app("subdir").mkpath
Dir.chdir(bundled_app("subdir")) do
bundle "install"
bundle "show"

expect(out).to include("rack (1.0.0)")
end
end
end

context "with deprecated features" do
before :each do
in_app_root
Expand Down