my $gitbranch=`git rev-parse --abbrev-ref HEAD`;
chomp($gitbranch);
my $last_branch_tag="";
my $last_release_tag="";
if ($gitbranch eq "master" || $gitbranch =~ "release/"){
$last_release_tag=get_last_release_tag ($gitbranch);
$last_branch_tag=$last_release_tag;
} else {
$last_release_tag=get_last_release_tag ($gitbranch);
$last_branch_tag=get_last_branch_tag ($gitbranch);
}
print ("$last_branch_tag $last_release_tag");
my $headcommit=`git rev-parse HEAD`;
if ($last_branch_tag eq "") {
print (" dirty");
} else {
my $tagcommit=`git rev-list -n 1 $last_branch_tag`;
if ($headcommit ne $tagcommit) {
print (" dirty");
}
}
print ("\n");
sub get_last_branch_tag () {
my $gitbranch = shift;
my $branchpattern = qr/^$gitbranch-\d+/;
my $delim="-";
return get_last_tag($gitbranch,$branchpattern,$delim)
}
sub get_last_release_tag () {
my $gitbranch = shift;
my $branchpattern = qr/^\d+\.\d+\.\d+$/;
my $delim="\\.";
return get_last_tag($gitbranch,$branchpattern,$delim)
}
sub get_last_tag () {
my $gitbranch = shift;
my $branchpattern = shift;
my $delim = shift;
my @versions;
my @tags;
open( $githashes, "git log --since 2019-10-01 --simplify-by-decoration --pretty='%H' ".$gitbranch." |" );
chomp( @hashes = <$githashes> );
close( $githashes );
foreach ( @hashes ) {
if ($gitbranch =~ "release/"){
$releaseid=(split('/',$gitbranch))[-1];
$grep_cmd = "git tag -l | grep \"" . "^" .$releaseid . "\" | ";
open( $gitver, "git show-ref --tags -d | grep ^" . $_ . " | sed -e 's,.* refs/tags/,,' | grep " .$releaseid ." |sed -e 's/\\^{}//' 2> /dev/null |" );
chomp( @tags = <$gitver> );
close( $gitver );
}
else{
open( $gitver, "git show-ref --tags -d | grep ^" . $_ . " | sed -e 's,.* refs/tags/,,' | sed -e 's/\\^{}//' 2> /dev/null |" );
chomp( @tags = <$gitver> );
close( $gitver );
}
foreach my $tag (@tags) {
if(grep(/$branchpattern/, $tag)) {
push @versions, $tag;
}
}
last if (scalar @versions >= 1);
}
my @sorted =