summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-08-30 11:59:01 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-09-08 10:46:55 -0700
commit0d25590168d352aaaf93a7ce9b66e67a5843b39d (patch)
treeddea34be6b6d18396cf6812dc99cb077505be71f
parent9a9a8173d2e35966cf915274d6940465af7c18eb (diff)
downloadbundler-0d25590168d352aaaf93a7ce9b66e67a5843b39d.tar.gz
Set CLI path options relative to the CWD on 2.0
-rw-r--r--lib/bundler/cli/check.rb2
-rw-r--r--lib/bundler/cli/common.rb17
-rw-r--r--lib/bundler/cli/install.rb13
-rw-r--r--lib/bundler/cli/package.rb2
-rw-r--r--lib/bundler/settings.rb9
-rw-r--r--spec/install/path_spec.rb25
6 files changed, 55 insertions, 13 deletions
diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb
index e572787dc4..607a5351d9 100644
--- a/lib/bundler/cli/check.rb
+++ b/lib/bundler/cli/check.rb
@@ -9,7 +9,7 @@ module Bundler
end
def run
- Bundler.settings.set_command_option_if_given :path, options[:path]
+ CLI::Common.set_path options[:path], :if_given
begin
definition = Bundler.definition
diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb
index 9d40ee9dfd..2edae86d05 100644
--- a/lib/bundler/cli/common.rb
+++ b/lib/bundler/cli/common.rb
@@ -98,5 +98,22 @@ module Bundler
clean &&= !Bundler.use_system_gems?
clean
end
+
+ def self.set_path(path, if_given = false)
+ return if if_given && path.nil?
+
+ path = Pathname.new(path)
+ if path.relative? && Bundler.feature_flag.path_relative_to_cwd?
+ path = path.expand_path
+ root = Bundler.root
+ path = begin
+ path.relative_path_from(root)
+ rescue ArgumentError
+ path
+ end
+ end
+
+ Bundler.settings.set_command_option :path, path.to_s
+ end
end
end
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index bb91b3de86..10f3a98002 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -71,8 +71,7 @@ module Bundler
if Bundler.use_system_gems?
Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed."
else
- absolute_path = File.expand_path(Bundler.configured_bundle_path.base_path)
- relative_path = absolute_path.sub(File.expand_path(".") + File::SEPARATOR, "." + File::SEPARATOR)
+ relative_path = Bundler.configured_bundle_path.base_path_relative_to_pwd
Bundler.ui.confirm "Bundled gems are installed into `#{relative_path}`"
end
@@ -168,12 +167,10 @@ module Bundler
end
def normalize_settings
- path = Bundler.feature_flag.path_relative_to_cwd? ? File.expand_path(options["path"]) : options["path"] if options["path"]
-
- 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, path
- Bundler.settings.set_command_option :path, "bundle" if options["standalone"] && Bundler.settings[:path].nil?
+ CLI::Common.set_path nil if options[:system]
+ CLI::Common.set_path "vendor/bundle" if options[:deployment]
+ CLI::Common.set_path options["path"], :if_given
+ CLI::Common.set_path "bundle" if options["standalone"] && Bundler.settings[:path].nil?
bin_option = options["binstubs"]
bin_option = nil if bin_option && bin_option.empty?
diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb
index 2dcd0e1e29..8aef0265e3 100644
--- a/lib/bundler/cli/package.rb
+++ b/lib/bundler/cli/package.rb
@@ -10,7 +10,7 @@ module Bundler
def run
Bundler.ui.level = "error" if options[:quiet]
- Bundler.settings.set_command_option_if_given :path, options[:path]
+ CLI::Common.set_path options[:path], :if_given
Bundler.settings.set_command_option_if_given :cache_all_platforms, options["all-platforms"]
Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"]
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 6e4f04f3ef..5329721b31 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -250,6 +250,15 @@ module Bundler
path
end
+ def base_path_relative_to_pwd
+ expanded_base_path = Pathname.new(base_path).expand_path(Bundler.root)
+ relative_path = expanded_base_path.relative_path_from(Pathname.pwd)
+ relative_path = Pathname.new(File.join(".", relative_path)) unless relative_path.to_s.start_with?("..")
+ relative_path
+ rescue ArgumentError
+ expanded_base_path
+ end
+
def validate!
return unless explicit_path && system_path
path = Bundler.settings.pretty_values_for(:path)
diff --git a/spec/install/path_spec.rb b/spec/install/path_spec.rb
index 8d42cba5b7..196cbb4ab7 100644
--- a/spec/install/path_spec.rb
+++ b/spec/install/path_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe "bundle install" do
Dir.chdir(dir) do
bundle! :install, forgotten_command_line_options(:path => "vendor/bundle")
- expect(out).to include("installed into `./vendor/bundle`")
+ expect(out).to include("installed into `../vendor/bundle`")
end
dir.rmtree
@@ -53,12 +53,31 @@ RSpec.describe "bundle install" do
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
+ it "installs the bundle relatively to current working directory", :bundler => "< 2" 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(out).to include("installed into `./vendor/bundle`")
expect(bundled_app("../vendor/bundle")).to be_directory
end
+ expect(the_bundle).to include_gems "rack 1.0.0"
+ end
+
+ it "installs the standalone bundle relative to the cwd" do
+ Dir.chdir(bundled_app.parent) do
+ bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true
+ expect(out).to include("installed into `./bundle`")
+ expect(bundled_app("../bundle")).to be_directory
+ expect(bundled_app("../bundle/ruby")).to be_directory
+ end
+
+ bundle! "config --delete path"
+
+ Dir.chdir(bundled_app("subdir").tap(&:mkpath)) do
+ bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true
+ expect(out).to include("installed into `./bundle`")
+ expect(bundled_app("subdir/bundle")).to be_directory
+ expect(bundled_app("subdir/bundle/ruby")).to be_directory
+ end
end
end
end