#!/usr/bin/perl

use strict;
use warnings;

#    Copyright 2012 Grant Street Group, All Rights Reserved.
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# PODNAME: gitc-diff-versions
# ABSTRACT: Show a diff between two version tags
our $VERSION = '0.60'; # VERSION

use App::Gitc::Util qw(
    current_branch
    current_branch_version
    is_valid_ref
    project_config
    version_tag_prefix
);

die "Project doesn't support version tagging"
    unless project_config()->{use_version_tags};

my ($branch, @versions) = @ARGV;
die "Unknown branch $branch" unless $branch =~ /^(master|test|stage|prod)$/;

push @versions, current_branch_version( $branch ) if @versions == 1;
@versions = map { version_tag_prefix( $branch ) . $_ } @versions;

for my $version_tag (@versions) {
    die "'$version_tag' is not a valid Git tag\n" if not is_valid_ref($version_tag);
}

exec "git diff --no-prefix @versions";

__END__

=pod

=head1 NAME

gitc-diff-versions - Show a diff between two version tags

=head1 VERSION

version 0.60

=head1 AUTHOR

Grant Street Group <developers@grantstreet.com>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Grant Street Group.

This is free software, licensed under:

  The GNU Affero General Public License, Version 3, November 2007

=cut
