From: Robert 'phaylon' Sedlacek Date: Thu, 3 May 2012 03:17:41 +0000 (+0000) Subject: Repositories::Git probe for locating git repositories and their information X-Git-Tag: v0.001_001~135 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5843e88666ca57e6d5bb038c7911dd792ce67334;p=scpubgit%2FSystem-Introspector.git Repositories::Git probe for locating git repositories and their information --- diff --git a/lib/System/Introspector/Repositories/Git.pm b/lib/System/Introspector/Repositories/Git.pm new file mode 100644 index 0000000..66776eb --- /dev/null +++ b/lib/System/Introspector/Repositories/Git.pm @@ -0,0 +1,53 @@ +package System::Introspector::Repositories::Git; +use Moo; + +sub gather { + my ($self) = @_; + my $pipe = $self->_open_locate_git_config_pipe; + my %location; + while (defined( my $line = <$pipe> )) { + chomp $line; + next unless $line =~ m{^(.+)/\.git/config$}; + my $base = $1; + $location{ $base } = $self->_gather_git_info($line); + } + return \%location; +} + +sub _gather_git_info { + my ($self, $config) = @_; + return { + config_file => $config, + config => $self->_gather_git_config($config), + }; +} + +sub _gather_git_config { + my ($self, $config) = @_; + my $pipe = $self->_open_git_config_pipe($config); + my %config; + while (defined( my $line = <$pipe> )) { + chomp $line; + my ($name, $value) = split m{=}, $line, 2; + $config{ $name } = $value; + } + return \%config; +} + +sub _open_git_config_pipe { + my ($self, $config) = @_; + my $command = "git config --file $config --list"; + open my $pipe, '-|', $command + or die "Unable to open pipe to '$command': $!\n"; + return $pipe; +} + +sub _open_locate_git_config_pipe { + my ($self) = @_; + my $command = 'locate .git/config'; + open my $pipe, '-|', $command + or die "Unable to open pipe to '$command': $!\n"; + return $pipe; +} + +1;