Created
February 15, 2011 01:46
-
-
Save founddrama/826955 to your computer and use it in GitHub Desktop.
Extracting the latest version in a `0.0.0.0` formatted versioning scheme.
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
# add the following under `[alias]` | |
latest-tag = "!sh -c 'git tag | get_latest_version.rb' -" | |
recent-tags = "!sh -c 'git tag | get_latest_version.rb -c ${1}' -" |
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
#!/usr/bin/env ruby | |
args = $*.to_a | |
if args.index("-c") | |
ct = [args[args.index("-c") + 1].to_i, 1].max | |
end | |
tags = $stdin.to_a | |
tags.collect! {|v| v = v.split('.') | |
v.collect! {|i| i.to_i} | |
} | |
tags.sort! {|a, b| a <=> b } | |
if ct | |
ct = [ct, tags.length].min | |
tag_range = tags[-ct..-1] | |
puts "LAST #{ct} VERSIONS:" | |
tag_range.each {|i| puts "#{i.join('.')}" } | |
else | |
puts "LATEST VERSION: #{tags[-1].join('.')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment