From c69452ecc970818cdabf045ce3c06ed8907aa559 Mon Sep 17 00:00:00 2001 From: Igor Bozato Date: Wed, 21 Jun 2017 15:36:59 -0300 Subject: Make `install --path` relative to the cwd --- lib/bundler/cli/install.rb | 2 +- lib/bundler/feature_flag.rb | 1 + lib/bundler/settings.rb | 1 + man/bundle-config.ronn | 2 ++ spec/install/path_spec.rb | 12 ++++++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index f0b821ed84..3f4b4f7239 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -170,7 +170,7 @@ module Bundler def normalize_settings Bundler.settings.set_command_option :path, nil if options[:system] Bundler.settings.set_command_option :path, "vendor/bundle" if options[:deployment] - Bundler.settings.set_command_option_if_given :path, options["path"] + Bundler.settings.set_command_option :path, Bundler.feature_flag.path_relative_to_cwd? ? File.expand_path(options["path"]) : options["path"] if options["path"] Bundler.settings.set_command_option :path, "bundle" if options["standalone"] && Bundler.settings[:path].nil? bin_option = options["binstubs"] diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index d6618379da..f7bb5d1cf8 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -44,6 +44,7 @@ module Bundler settings_flag(:list_command) { bundler_2_mode? } settings_flag(:lockfile_uses_separate_rubygems_sources) { bundler_2_mode? } settings_flag(:only_update_to_newer_versions) { bundler_2_mode? } + settings_flag(:path_relative_to_cwd) { bundler_2_mode? } settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") } settings_flag(:prefer_gems_rb) { bundler_2_mode? } settings_flag(:print_only_version_number) { bundler_2_mode? } diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 5f01e7a376..6e4f04f3ef 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -43,6 +43,7 @@ module Bundler no_install no_prune only_update_to_newer_versions + path_relative_to_cwd path.system plugins prefer_gems_rb diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index f1f3062aea..3d3063dfb3 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -218,6 +218,8 @@ learn more about their operation in [bundle install(1)][bundle-install]. is used, defaults to vendor/bundle. * `path.system` (`BUNDLE_PATH__SYSTEM`): Whether Bundler will install gems into the default system path (`Gem.dir`). +* `path_relative_to_cwd` (`PATH_RELATIVE_TO_CWD`) + Makes `--path` relative to the CWD instead of the `Gemfile`. * `plugins` (`BUNDLE_PLUGINS`): Enable Bundler's experimental plugin system. * `prefer_gems_rb` (`BUNDLE_PREFER_GEMS_RB`) diff --git a/spec/install/path_spec.rb b/spec/install/path_spec.rb index fb356899a6..2de2f5983d 100644 --- a/spec/install/path_spec.rb +++ b/spec/install/path_spec.rb @@ -49,6 +49,18 @@ RSpec.describe "bundle install" do expect(vendored_gems("gems/rack-1.0.0")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" end + + context "with path_relative_to_cwd set to true" do + before { bundle! "config path_relative_to_cwd true" } + + it "installs the bundle relatively to current working directory" do + Dir.chdir(bundled_app.parent) do + bundle "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle" + expect(out).to include("installed into ./vendor/bundle") + expect(Dir.exist?("vendor/bundle")).to be true + end + end + end end describe "when BUNDLE_PATH or the global path config is set" do -- cgit v1.2.1