Skip to content

Commit

Permalink
Use branch --contains instead of describe and filter tags by checking…
Browse files Browse the repository at this point in the history
… to see if the tag is contained by the current branch

Conflicts:
	lib/thor-scmversion/git_version.rb
  • Loading branch information
capoferro committed Jul 23, 2013
1 parent 476e0e3 commit e94b85c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/thor-scmversion/git_version.rb
Expand Up @@ -5,12 +5,17 @@ class GitVersion < ScmVersion
class << self
def all_from_path(path)
Dir.chdir(path) do
tags = Open3.popen3("git describe --tags --match *.*.*") { |stdin, stdout, stderr| stdout.read }.split(/\n/)
version_tags = tags.select { |tag| tag.match(ScmVersion::VERSION_FORMAT) }
version_tags.collect { |tag| from_tag(tag) }.sort.reverse
tags = Open3.popen3("git tag") { |stdin, stdout, stderr| stdout.read }.split(/\n/)
tags.select { |tag| tag.match(ScmVersion::VERSION_FORMAT) }
.collect { |tag| from_tag(tag) }
.select { |tag| contained_in_current_branch?(tag) }.sort.reverse
end
end

def contained_in_current_branch?(tag)
ShellUtils.sh("git branch --contains #{tag}") =~ /\*/
end

def retrieve_tags
ShellUtils.sh("git fetch --all")
end
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/thor-scmversion/git_version_spec.rb
@@ -0,0 +1,13 @@
require 'spec_helper'

module ThorSCMVersion
describe GitVersion do
it "should detect if a commit is contained on a given branch" do
ShellUtils.stub(:sh).and_return(<<OUT)
* constrain_bump_to_branch
master
OUT
expect(GitVersion.contained_in_current_branch?('0.0.1')).to be_true
end
end
end

0 comments on commit e94b85c

Please sign in to comment.