Skip to content

Instantly share code, notes, and snippets.

@whylom
Created December 8, 2011 20:53
Show Gist options
  • Save whylom/1448530 to your computer and use it in GitHub Desktop.
Save whylom/1448530 to your computer and use it in GitHub Desktop.
Ruby method that shells out to git describe and formats results
def get_tag_info(commit)
info = `git describe --tags #{commit}`.chomp
if info[/(.*)-(\d+)-g([a-z0-9]{7})/]
matches = Regexp.last_match
last_tag = matches[1]
commits_since_tag = matches[2]
noun = (commits_since_tag.to_i == 1) ? 'commit' : 'commits'
"#{last_tag} + #{commits_since_tag} #{noun}"
else
info
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment