Created
April 17, 2009 16:07
-
-
Save johnschult/97103 to your computer and use it in GitHub Desktop.
Returns the git tag that has the same hash as the head of the branch parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'git' | |
module Git | |
class Lib | |
# finds a tag with the same hash as the specified branch's head (if any) | |
def tag_for_head(branch) | |
tag = nil | |
head_hash = command('show-ref', ['--hash', "#{branch}"]) | |
command('show-ref', ['--tags']).each do |r| | |
if m = /^#{head_hash}\srefs\/tags\/(.*)$/.match(r) | |
tag = m[1] | |
end | |
end | |
tag | |
end | |
end | |
class Base | |
# finds a tag with the same hash as the specified branch's head (if any) | |
def tag_for_head(branch='master') | |
self.lib.tag_for_head(branch) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment