Skip to content

Commit

Permalink
Item13887: Improvements to tools/branches
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Nov 11, 2016
1 parent fc1d4ca commit 5adc0a8
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions core/tools/branches
Expand Up @@ -11,60 +11,84 @@ use warnings;
use LWP::Simple;
use Data::Dumper;

my %items;
my %seen;

sub clean {
map { s/^[\s\*]*\s// } @_;
map { s/\s*$// } @_;
return @_;
}

sub descr {

#print "DESCR for @_\n";
$_ = `git config branch.@_.description`;
s/\s*$//;
return $_;
};
}

sub summary {
my $it = shift;

#print "SUMMARY for @_\n";
my $url = "http://foswiki.org/Tasks/ItemSummaryQuery?item=@_;skin=text";
return $items{$it} if $items{$it};
my $url = "http://foswiki.org/Tasks/ItemSummaryQuery?item=$it;skin=text";
my $description = get $url;
$description =~ s#<b>.*</b>\n##;
$items{$it} = $description;
return $description;
}

sub indent {
$_ = shift;
s/^/ /mg;
return $_;
};
}

my @branches = clean `git branch --color=never --list --all`;

#print Data::Dumper::Dumper( \@branches );
my %merged = map { $_ => 1 } clean `git branch --color=never --merged`;

#print Data::Dumper::Dumper( \%merged );

for my $branch (@branches) {

next if $branch =~ /HEAD/;

# Don't display upstream branches that we already have locally
$seen{$branch} = 1;
my ($remote) = $branch =~ m/remotes\/origin\/(.*)/;
next if ( $remote && $seen{$remote} );

$branch =~ s#^remotes/##;
my $asis = `git branch --list -a --color=always $branch`;
$asis =~ s/\s*$//;

# Get the upstream status - gone, ahead or behind
my $status = `git branch --list -a -vv $branch`;
my ($upstream) = $status =~ m/.*?\[([^\]]+)\]/;
my ($state) = $upstream =~ m/:\s(.*)$/ if ($upstream);

print " $asis";
print " \033[33m(merged)\033[0m" if ($merged{$branch} and $branch ne "master");
print " \033[33m(merged)\033[0m"
if ( $merged{$branch} and $branch ne "master" );
print " \033[104m($state)\033[0m" if $state;
print "\n";
next if $branch =~ m/Release/;
my $desc = descr $branch;
print indent $desc."\n" if $desc;
print indent $desc. "\n" if $desc;
if ( $branch =~ m/(Item(?:[0-9]){3,5})/ ) {
print indent summary $1;
}
elsif ($desc =~ m/(Item(?:[0-9]){3,5})/ ) {
elsif ( $desc =~ m/(Item(?:[0-9]){3,5})/ ) {
print indent summary $1;
}

print "\n";
}


__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down

0 comments on commit 5adc0a8

Please sign in to comment.