Skip to content

Instantly share code, notes, and snippets.

@founddrama
Created February 15, 2011 01:46
Show Gist options
  • Save founddrama/826955 to your computer and use it in GitHub Desktop.
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.
# 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}' -"
#!/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