[rubygems/rubygems] Centralize logic using Pathname#relative_path_from
To avoid potential crashes when trying to jump from a drive to another on Windows, and take the change refactor things a bit. https://github.com/rubygems/rubygems/commit/7c9a9a431a
This commit is contained in:
parent
a812f1fed0
commit
bece880874
@ -29,7 +29,7 @@ module Bundler
|
|||||||
Bundler.ui.warn "Install missing gems with `bundle install`"
|
Bundler.ui.warn "Install missing gems with `bundle install`"
|
||||||
exit 1
|
exit 1
|
||||||
elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle?
|
elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle?
|
||||||
Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present"
|
Bundler.ui.error "This bundle has been frozen, but there is no #{SharedHelpers.relative_lockfile_path} present"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
Bundler.load.lock(:preserve_unknown_sections => true) unless options[:"dry-run"]
|
Bundler.load.lock(:preserve_unknown_sections => true) unless options[:"dry-run"]
|
||||||
|
@ -29,7 +29,7 @@ module Bundler
|
|||||||
flag ||= "--frozen flag" if options[:frozen]
|
flag ||= "--frozen flag" if options[:frozen]
|
||||||
flag ||= "deployment setting"
|
flag ||= "deployment setting"
|
||||||
raise ProductionError, "The #{flag} requires a lockfile. Please make " \
|
raise ProductionError, "The #{flag} requires a lockfile. Please make " \
|
||||||
"sure you have checked your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} into version control " \
|
"sure you have checked your #{SharedHelpers.relative_lockfile_path} into version control " \
|
||||||
"before deploying."
|
"before deploying."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -405,13 +405,13 @@ module Bundler
|
|||||||
msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
|
msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
|
||||||
msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any?
|
msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any?
|
||||||
msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any?
|
msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any?
|
||||||
msg << "\n\nRun `bundle install` elsewhere and add the updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control.\n"
|
msg << "\n\nRun `bundle install` elsewhere and add the updated #{SharedHelpers.relative_gemfile_path} to version control.\n"
|
||||||
|
|
||||||
unless explicit_flag
|
unless explicit_flag
|
||||||
suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env)
|
suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env)
|
||||||
"bundle config set frozen false"
|
"bundle config set frozen false"
|
||||||
end
|
end
|
||||||
msg << "If this is a development machine, remove the #{Bundler.default_gemfile.relative_path_from(SharedHelpers.pwd)} " \
|
msg << "If this is a development machine, remove the #{SharedHelpers.relative_lockfile_path} " \
|
||||||
"freeze by running `#{suggested_command}`." if suggested_command
|
"freeze by running `#{suggested_command}`." if suggested_command
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ module Bundler
|
|||||||
|
|
||||||
out << "\n## Gemfile\n"
|
out << "\n## Gemfile\n"
|
||||||
gemfiles.each do |gemfile|
|
gemfiles.each do |gemfile|
|
||||||
out << "\n### #{Pathname.new(gemfile).relative_path_from(SharedHelpers.pwd)}\n\n"
|
out << "\n### #{SharedHelpers.relative_path_to(gemfile)}\n\n"
|
||||||
out << "```ruby\n" << read_file(gemfile).chomp << "\n```\n"
|
out << "```ruby\n" << read_file(gemfile).chomp << "\n```\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
out << "\n### #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}\n\n"
|
out << "\n### #{SharedHelpers.relative_path_to(Bundler.default_lockfile)}\n\n"
|
||||||
out << "```\n" << read_file(Bundler.default_lockfile).chomp << "\n```\n"
|
out << "```\n" << read_file(Bundler.default_lockfile).chomp << "\n```\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,20 +55,13 @@ module Bundler
|
|||||||
if spec.source.instance_of?(Source::Path) && spec.source.path.absolute?
|
if spec.source.instance_of?(Source::Path) && spec.source.path.absolute?
|
||||||
full_path
|
full_path
|
||||||
else
|
else
|
||||||
relative_path_from(Bundler.root.join(bundler_path), :to => full_path) || full_path
|
SharedHelpers.relative_path_to(full_path, :from => Bundler.root.join(bundler_path))
|
||||||
end
|
end
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
|
error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
|
||||||
raise Gem::InvalidSpecificationException.new(error_message)
|
raise Gem::InvalidSpecificationException.new(error_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_path_from(source, to:)
|
|
||||||
Pathname.new(to).relative_path_from(source).to_s
|
|
||||||
rescue ArgumentError
|
|
||||||
# on Windows, if source and destination are on different drivers, there's no relative path from one to the other
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def define_path_helpers
|
def define_path_helpers
|
||||||
<<~'END'
|
<<~'END'
|
||||||
unless defined?(Gem)
|
unless defined?(Gem)
|
||||||
|
@ -68,7 +68,7 @@ module Bundler
|
|||||||
|
|
||||||
if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
|
if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
|
||||||
raise LockfileError, "Your lockfile contains merge conflicts.\n" \
|
raise LockfileError, "Your lockfile contains merge conflicts.\n" \
|
||||||
"Run `git checkout HEAD -- #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` first to get a clean lock."
|
"Run `git checkout HEAD -- #{SharedHelpers.relative_lockfile_path}` first to get a clean lock."
|
||||||
end
|
end
|
||||||
|
|
||||||
lockfile.split(/(?:\r?\n)+/) do |line|
|
lockfile.split(/(?:\r?\n)+/) do |line|
|
||||||
@ -92,7 +92,7 @@ module Bundler
|
|||||||
@specs = @specs.values.sort_by!(&:full_name)
|
@specs = @specs.values.sort_by!(&:full_name)
|
||||||
rescue ArgumentError => e
|
rescue ArgumentError => e
|
||||||
Bundler.ui.debug(e)
|
Bundler.ui.debug(e)
|
||||||
raise LockfileError, "Your lockfile is unreadable. Run `rm #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` " \
|
raise LockfileError, "Your lockfile is unreadable. Run `rm #{SharedHelpers.relative_lockfile_path}` " \
|
||||||
"and then `bundle install` to generate a new lockfile."
|
"and then `bundle install` to generate a new lockfile."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -197,6 +197,21 @@ module Bundler
|
|||||||
filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } }
|
filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def relative_gemfile_path
|
||||||
|
relative_path_to(Bundler.default_gemfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
def relative_lockfile_path
|
||||||
|
relative_path_to(Bundler.default_lockfile)
|
||||||
|
end
|
||||||
|
|
||||||
|
def relative_path_to(destination, from: pwd)
|
||||||
|
Pathname.new(destination).relative_path_from(from).to_s
|
||||||
|
rescue ArgumentError
|
||||||
|
# on Windows, if source and destination are on different drivers, there's no relative path from one to the other
|
||||||
|
destination
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def validate_bundle_path
|
def validate_bundle_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user