#!/usr/bin/ruby

require 'tins/xt'
require 'term/ansicolor'
include Tins::GO

$opts = go 'r:v'

class String
  include Term::ANSIColor
end

regexp = $opts[?r] && Regexp.new($opts[?r]) || /^v((?:\d+\.)*\d+)/

versions = `git tag`.lines.map(&:chomp).grep(regexp).sort_by { |x|
  x[regexp, 1].version
}.reverse
versions.each_cons(2) do |new, old|
  puts "Version #{new}".red.bold
  if $opts[?v]
    puts `git log --color --stat -u #{old}..#{new}`
  else
    puts `git log --color --stat #{old}..#{new}`
  end
end