diff options
author | Georg Gadinger <nilsding@nilsding.org> | 2018-01-19 17:32:49 +0100 |
---|---|---|
committer | Georg Gadinger <nilsding@nilsding.org> | 2018-01-19 17:39:05 +0100 |
commit | f81ee89687d0764cd28355b6455fda84b59592f0 (patch) | |
tree | d0f3d23e39caeea7d35ec0db6d20540a9fb1743b | |
parent | d2ff01867b5d4fcbbf6e6dae1ddcc155392909a3 (diff) | |
download | bundler-f81ee89687d0764cd28355b6455fda84b59592f0.tar.gz |
[Init] Check if the current directory is writable
-rw-r--r-- | lib/bundler/cli/init.rb | 5 | ||||
-rw-r--r-- | spec/commands/init_spec.rb | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/bundler/cli/init.rb b/lib/bundler/cli/init.rb index fa53e7c74b..40df797269 100644 --- a/lib/bundler/cli/init.rb +++ b/lib/bundler/cli/init.rb @@ -13,6 +13,11 @@ module Bundler exit 1 end + unless File.writable?(Dir.pwd) + Bundler.ui.error "Can not create #{gemfile} as the current directory is not writable." + exit 1 + end + if options[:gemspec] gemspec = File.expand_path(options[:gemspec]) unless File.exist?(gemspec) diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb index c1cd7b90c8..7a032c09aa 100644 --- a/spec/commands/init_spec.rb +++ b/spec/commands/init_spec.rb @@ -64,6 +64,22 @@ RSpec.describe "bundle init" do end end + context "when the dir is not writable by the current user" do + let(:subdir) { "child_dir" } + + it "notifies the user that it can not write to it" do + FileUtils.mkdir bundled_app(subdir) + FileUtils.chmod "a-w", bundled_app(subdir) + + Dir.chdir bundled_app(subdir) do + bundle :init + end + + expect(out).to include("directory is not writable") + expect(bundled_app(subdir)).to be_empty + end + end + context "when a gems.rb file exists in a parent directory", :bundler => ">= 2" do let(:subdir) { "child_dir" } |