From: Robert 'phaylon' Sedlacek Date: Tue, 18 Sep 2012 19:33:57 +0000 (+0000) Subject: gather current branch and last commit X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6a1a86c691d41c07337d4b471b601a9b5f935152;p=scpubgit%2FSystem-Introspector.git gather current branch and last commit --- diff --git a/lib/System/Introspector/Probe/Repositories/Git.pm b/lib/System/Introspector/Probe/Repositories/Git.pm index 1ac056e..76b41f1 100644 --- a/lib/System/Introspector/Probe/Repositories/Git.pm +++ b/lib/System/Introspector/Probe/Repositories/Git.pm @@ -29,20 +29,44 @@ sub gather { sub _gather_git_info { my ($self, $config) = @_; + (my $git_dir = $config) =~ s{/config$}{}; return { config_file => $config, + current => transform_exceptions { + $self->_gather_current_state($git_dir); + }, config => transform_exceptions { $self->_gather_git_config($config); }, tracked => transform_exceptions { - $self->_gather_track_info($config); + $self->_gather_track_info($git_dir); }, }; } +sub _gather_current_state { + my ($self, $git_dir) = @_; + local $ENV{GIT_DIR} = $git_dir; + my ($active_branch) = + map { s{^\s*\*\s+}{}; $_ } + grep { m{^\s*\*\s+(.+)$} } + lines_from_command ['git', 'branch']; + return { __error__ => 'No active branch' } + unless $active_branch; + my @log_lines = lines_from_command [ + 'git', 'log', + '-n1', + '--date=iso', + '--pretty=fuller', + ]; + return { + branch => $active_branch, + commit => [@log_lines], + }; +} + sub _gather_track_info { - my ($self, $config) = @_; - (my $git_dir = $config) =~ s{/config$}{}; + my ($self, $git_dir) = @_; return $self->_find_tracking($git_dir); }