Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…

#!/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"; |