/
Git.pm6
24 lines (20 loc) · 845 Bytes
/
Git.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use Distribution::IO;
# This targets a LOCAL git path. An additional role could provide access to non-local remotes
role Distribution::IO::Proc::Git does Distribution::IO {
my sub run-git(*@cmd, :%env = %*ENV, :$cwd, Bool :$bin) {
my $proc = $*DISTRO.is-win
?? run('cmd', '/c', 'git', |@cmd, :out, :err, :$bin, :$cwd, :%env)
!! run('git', |@cmd, :out, :err, :$bin, :$cwd, :%env);
my $out = |$proc.out.slurp-rest(:$bin);
my $err = |$proc.err.slurp-rest(:$bin);
$ = $proc.out.close unless $err;
$ = $proc.err.close;
%( :$out, :$err )
}
method ls-files {
state @paths = run-git('ls-files', :cwd($.prefix))<out>.lines;
}
method slurp-rest($name-path, Bool :$bin) {
run-git('show', "HEAD:$name-path", :$bin, :cwd($.prefix))<out>;
}
}