Skip to content

Instantly share code, notes, and snippets.

@bbarker
Last active March 31, 2016 13:23
Show Gist options
  • Save bbarker/b46ca451595d685d57fe59e76bed3373 to your computer and use it in GitHub Desktop.
Save bbarker/b46ca451595d685d57fe59e76bed3373 to your computer and use it in GitHub Desktop.
A staging summary script organized by file
#!/usr/bin/perl -w
use warnings;
use strict;
use Cwd;
my $git_out = `git log --name-status --pretty=oneline master..develop`;
my %modifications;
my %messages;
my $last_message;
foreach my $git_line (split(/\n/, $git_out)) {
if ($git_line =~ /([a-z\d]{40})(.*)/) {
$last_message = $2;
$last_message =~ s/^\s+|\s+$//g; #trim space
}
elsif ($git_line =~ /([A-Z])\s+(.*)/) {
@{$messages{$2}} = exists $messages{$2} ?
(@{$messages{$2}}, ($last_message)) : ($last_message);
@{$modifications{$2}} = exists $modifications{$2} ?
(@{$modifications{$2}}, ($1)) : ($1);
}
}
my $dir = getcwd();
my $repo;
if ($dir =~ /.*[\/\\](\S+)$/) {
$repo = $1;
}
print "$repo\n";
foreach my $file (sort keys %messages) {
my $file_message = join(',', map {"[$_]"} @{$messages{$file}});
my $file_mods = join('/', @{$modifications{$file}});
print " $file ($file_mods): $file_message\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment