Skip to content

Commit

Permalink
Merge pull request #115 from pivotalzergling/master
Browse files Browse the repository at this point in the history
Fixes bug: Should not push HEAD if tag pattern matching fails
  • Loading branch information
kmayer committed Nov 24, 2012
2 parents 487d9e9 + 5ac01b2 commit 6d03103
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'rake/dsl_definition'

module Git
class NoTagFoundError < Exception; end

include Rake::DSL

def git_clone(repos, dir)
Expand Down Expand Up @@ -34,7 +36,7 @@ def git_rev_parse(ref)

def git_tag(glob)
return nil if glob.nil?
%x{git tag -l '#{glob}'}.split("\n").last
%x{git tag -l '#{glob}'}.split("\n").last || (raise NoTagFoundError, "No tag found [#{glob}]")
end

def git_revision(repo)
Expand Down
8 changes: 5 additions & 3 deletions spec/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class GitTest; include Git; end
subject.should_receive("`").with("git tag -l 'pattern*'") { "x\n\y\n\z\n" }
subject.git_tag('pattern*').should == "z"
end
it "returns nil if no tags match the pattern" do
it "raises exception if no tags match the pattern" do
subject.should_receive("`").with("git tag -l 'pattern*'") { "\n" }
subject.git_tag('pattern*').should == nil
expect {
subject.git_tag('pattern*')
}.to raise_error(Git::NoTagFoundError)
end
it "returns nil for a nil tag" do
it "returns nil for a nil glob" do
subject.should_not_receive("`").with("git tag -l ''") { "\n" }
subject.git_tag(nil).should == nil
end
Expand Down
6 changes: 4 additions & 2 deletions spec/heroku_san/stage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@

describe "#push" do
it "deploys to heroku" do
subject.should_receive(:git_push).with(git_parsed_tag(subject.tag), subject.repo, [])
subject.should_receive(:git_parsed_tag).with(nil) {'tag'}
subject.should_receive(:git_push).with('tag', subject.repo, [])
subject.push
end

Expand All @@ -89,7 +90,8 @@
end

it "deploys with --force" do
subject.should_receive(:git_push).with(git_parsed_tag(subject.tag), subject.repo, %w[--force])
subject.should_receive(:git_parsed_tag).with(nil) {'tag'}
subject.should_receive(:git_push).with('tag', subject.repo, %w[--force])
subject.push(nil, :force)
end

Expand Down

0 comments on commit 6d03103

Please sign in to comment.