1 package System::Introspector::Repositories::Git;
6 default => sub { '/' },
11 my $pipe = $self->_open_locate_git_config_pipe;
13 while (defined( my $line = <$pipe> )) {
15 next unless $line =~ m{^(.+)/\.git/config$};
17 $location{ $base } = $self->_gather_git_info($line);
22 sub _gather_git_info {
23 my ($self, $config) = @_;
25 config_file => $config,
26 config => $self->_gather_git_config($config),
27 tracked => $self->_gather_track_info($config),
31 sub _gather_track_info {
32 my ($self, $config) = @_;
33 (my $git_dir = $config) =~ s{/config$}{};
34 my @tracked = $self->_find_tracking($git_dir);
38 my ($self, $dir) = @_;
40 q{GIT_DIR=%s git for-each-ref --format '%s' refs/heads},
42 q{OK %(refname:short) %(upstream:short)};
43 my @lines = `$command 2>&1`;
46 for my $line (@lines) {
47 if ($line =~ m{^OK\s+(\S+)\s+(\S+)?$}) {
48 my ($local, $remote) = ($1, $2);
52 => $self->_find_changes($dir, $local, $remote),
54 => $self->_find_commits($dir, $local, $remote),
58 return { error => join "\n", @lines };
61 return { branches => \%branch };
65 my ($self, $dir, $local, $remote) = @_;
66 return { error => "No remote" }
67 unless defined $remote;
69 q{GIT_DIR=%s git log --oneline %s..%s},
70 $dir, $remote, $local;
71 my @lines = `$command 2>&1`;
76 my ($self, $dir, $local, $remote) = @_;
77 return { error => "No remote" }
78 unless defined $remote;
80 q{GIT_DIR=%s git diff --name-only %s %s},
81 $dir, $local, $remote;
82 my @lines = `$command 2>&1`;
87 sub _gather_git_config {
88 my ($self, $config) = @_;
89 my $pipe = $self->_open_git_config_pipe($config);
91 while (defined( my $line = <$pipe> )) {
93 my ($name, $value) = split m{=}, $line, 2;
94 $config{ $name } = $value;
99 sub _open_git_config_pipe {
100 my ($self, $config) = @_;
101 my $command = "git config --file $config --list";
102 open my $pipe, '-|', $command
103 or die "Unable to open pipe to '$command': $!\n";
107 sub _open_locate_git_config_pipe {
109 my $root = $self->root;
111 my $command = sprintf q{locate --regex '^%s/.*\\.git/config$'}, $root;
112 open my $pipe, '-|', $command
113 or die "Unable to open pipe to '$command': $!\n";
123 System::Introspector::Repositories::Git - Gather Git repository info
127 Find Git repositories and gathers their information.
133 This is the root path for the search of git directories. Defaults to C</>.
139 =item L<System::Introspector>