Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 40 lines (31 sloc) 902 Bytes
#!/usr/bin/env perl
# martin, 2018-12-20, 2019-01-12
# ... prints committer info from .git/config
use strict;
use warnings;
use utf8;
use Cwd qw/getcwd/;
use Mojo::File;
sub extract_committer {
my (@lines) = split(/\n/, shift);
my (%config, $current_key);
for (@lines) {
if (/^\[(.*?)\]$/) {
# like: "[core]"
$current_key = $1;
} elsif (/^\s*(.*?) = (.*?)$/) {
# like: " bare = false"
$config{$current_key}->{$1} = $2;
}
}
unless (defined $config{user}->{email}
&& defined $config{user}->{name}) {
die "Your .git/config does not seem to have a valid user entry\n";
}
return $config{user}->%*;
}
my $conf = Mojo::File->new(getcwd)->child('.git/config');
die "Looks like $conf does not exist\n" unless (-e $conf);
my $data = $conf->slurp;
my %committer = extract_committer($data);
print "$committer{name} <$committer{email}>\n";