Permalink
Browse files

Git#push when remote does not exist returns silently

  • Loading branch information...
1 parent 4bffaa3 commit 2ac8ca8e33d98ec2e323f0f6a02910ed11cb80d5 @bryan-ash bryan-ash committed Oct 22, 2011
Showing with 32 additions and 16 deletions.
  1. +1 −0 lib/kumade/git.rb
  2. +31 −16 spec/kumade/git_spec.rb
View
@@ -11,6 +11,7 @@ def self.environments
end
def push(branch, remote = 'origin', force = false)
+ return unless remote_exists?(remote)
command = ["git push"]
command << "-f" if force
command << remote
View
@@ -43,27 +43,42 @@
describe Kumade::Git, "#push", :with_mock_outputter do
let(:branch) { 'branch' }
let(:remote) { 'my-remote' }
- let(:command_line) { stub("Kumade::CommandLine instance", :run_or_error => true) }
- before do
- Kumade::CommandLine.stubs(:new => command_line)
- end
+ context "when the remote exists" do
+ let(:command_line) { stub("Kumade::CommandLine instance", :run_or_error => true) }
- it "pushes to the correct remote" do
- subject.push(branch, remote)
- Kumade::CommandLine.should have_received(:new).with("git push #{remote} #{branch}")
- command_line.should have_received(:run_or_error).once
- end
+ before do
+ Kumade::CommandLine.stubs(:new => command_line)
+ subject.stubs(:remote_exists? => true)
+ end
+
+ it "pushes to the correct remote" do
+ subject.push(branch, remote)
+ Kumade::CommandLine.should have_received(:new).with("git push #{remote} #{branch}")
+ command_line.should have_received(:run_or_error).once
+ end
- it "can force push" do
- subject.push(branch, remote, true)
- Kumade::CommandLine.should have_received(:new).with("git push -f #{remote} #{branch}")
- command_line.should have_received(:run_or_error).once
+ it "can force push" do
+ subject.push(branch, remote, true)
+ Kumade::CommandLine.should have_received(:new).with("git push -f #{remote} #{branch}")
+ command_line.should have_received(:run_or_error).once
+ end
+
+ it "prints a success message" do
+ subject.push(branch, remote)
+ Kumade.configuration.outputter.should have_received(:success).with("Pushed #{branch} -> #{remote}")
+ end
end
- it "prints a success message" do
- subject.push(branch, remote)
- Kumade.configuration.outputter.should have_received(:success).with("Pushed #{branch} -> #{remote}")
+ context "when the remote does not exist" do
+ before do
+ subject.stubs(:remote_exists? => false)
+ end
+
+ it "returns silently" do
+ subject.push(branch)
+ Kumade::CommandLine.should have_received(:new).never
+ end
end
end

0 comments on commit 2ac8ca8

Please sign in to comment.