From d4d4ed64736e99e15159e33751078b1703ca94bd Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 7 Dec 2017 11:02:43 -0800 Subject: [PATCH] (#9137) Exit 0 if vagrant destroy finds no running vms This commit reverts the behavior of `vagrant destroy` to exit 0 if no running vms were found when the destroy command is run. --- plugins/commands/destroy/command.rb | 4 ++++ test/unit/plugins/commands/destroy/command_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/commands/destroy/command.rb b/plugins/commands/destroy/command.rb index d63c0b26b..f9e06c65b 100644 --- a/plugins/commands/destroy/command.rb +++ b/plugins/commands/destroy/command.rb @@ -60,6 +60,10 @@ module VagrantPlugins # Nothing was declined return 0 if declined == 0 + # Everything was declined, and all states are `not_created` + return 0 if declined == machines.length && + declined == init_states.values.count(:not_created) + # Everything was declined, state was not changed return 1 if declined == machines.length diff --git a/test/unit/plugins/commands/destroy/command_test.rb b/test/unit/plugins/commands/destroy/command_test.rb index 01ea97236..6892b3ac4 100644 --- a/test/unit/plugins/commands/destroy/command_test.rb +++ b/test/unit/plugins/commands/destroy/command_test.rb @@ -51,6 +51,14 @@ describe VagrantPlugins::CommandDestroy::Command do expect(subject.execute).to eq(0) end + it "exits 0 if vms are not created" do + allow_any_instance_of(Vagrant::BatchAction).to receive(:action) .with(machine, :destroy, anything) + allow(machine.state).to receive(:id).and_return(:not_created) + + expect(machine.state).to receive(:id).and_return(:not_created) + expect(subject.execute).to eq(0) + end + it "exits 1 if a vms destroy was declined" do allow_any_instance_of(Vagrant::BatchAction).to receive(:action) .with(machine, :destroy, anything)