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);
}