Fix vagrant_cwd warnings
Prior to this commit, if a user ran a vagrant command within a subdir, it would warn about the cwd changing which is not actually the case. This commit adds an additional check to see if vagrant is being invoked within a subdirectory so that it doesn't warn the user.
This commit is contained in:
parent
5333e60e2d
commit
1b4d7848bc
|
@ -577,13 +577,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
if vagrant_cwd.nil?
|
if vagrant_cwd.nil?
|
||||||
File.write(vagrant_cwd_filepath, @env.cwd)
|
File.write(vagrant_cwd_filepath, @env.root_path)
|
||||||
elsif vagrant_cwd != @env.cwd.to_s
|
elsif vagrant_cwd != @env.root_path.to_s
|
||||||
ui.warn(I18n.t(
|
ui.warn(I18n.t(
|
||||||
'vagrant.moved_cwd',
|
'vagrant.moved_cwd',
|
||||||
old_wd: vagrant_cwd,
|
old_wd: vagrant_cwd,
|
||||||
current_wd: @env.cwd.to_s))
|
current_wd: @env.root_path.to_s))
|
||||||
File.write(vagrant_cwd_filepath, @env.cwd)
|
File.write(vagrant_cwd_filepath, @env.root_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -338,7 +338,7 @@ describe Vagrant::Machine do
|
||||||
expect(subject.ui).to_not have_received(:warn)
|
expect(subject.ui).to_not have_received(:warn)
|
||||||
|
|
||||||
# Whenever the machine is run on a different directory, the user is warned
|
# Whenever the machine is run on a different directory, the user is warned
|
||||||
allow(env).to receive(:cwd).and_return('/a/new/path')
|
allow(env).to receive(:root_path).and_return('/a/new/path')
|
||||||
instance.action(action_name)
|
instance.action(action_name)
|
||||||
|
|
||||||
expect(subject.ui).to have_received(:warn) do |warn_msg|
|
expect(subject.ui).to have_received(:warn) do |warn_msg|
|
||||||
|
@ -346,6 +346,28 @@ describe Vagrant::Machine do
|
||||||
expect(warn_msg).to include('/a/new/path')
|
expect(warn_msg).to include('/a/new/path')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "if in a subdir" do
|
||||||
|
let (:data_dir) { env.cwd }
|
||||||
|
|
||||||
|
it 'should not warn if vagrant is run in subdirectory' do
|
||||||
|
action_name = :up
|
||||||
|
callable = lambda { |_env| }
|
||||||
|
original_cwd = env.cwd.to_s
|
||||||
|
|
||||||
|
allow(provider).to receive(:action).with(action_name).and_return(callable)
|
||||||
|
allow(subject.ui).to receive(:warn)
|
||||||
|
|
||||||
|
instance.action(action_name)
|
||||||
|
|
||||||
|
expect(subject.ui).to_not have_received(:warn)
|
||||||
|
# mock out cwd to be subdir and ensure no warn is printed
|
||||||
|
allow(env).to receive(:cwd).and_return("#{original_cwd}/a/new/path")
|
||||||
|
|
||||||
|
instance.action(action_name)
|
||||||
|
expect(subject.ui).to_not have_received(:warn)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#action_raw" do
|
describe "#action_raw" do
|
||||||
|
|
Loading…
Reference in New Issue