Skip to content

Instantly share code, notes, and snippets.

@johnschult
Created April 17, 2009 16:07
Show Gist options
  • Save johnschult/97103 to your computer and use it in GitHub Desktop.
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
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