git
=title class Zef::Service::Shell::git
=subtitle A git based implementation of the Fetcher and Extractor interfaces
Synopsis
use Zef;
use Zef::Service::Shell::git;
my $git = Zef::Service::Shell::git.new;
# Fetch the git repository
my $tag-or-sha = "@v0.9.0";
my $source = "https://github.com/ugexe/zef.git{$tag-or-sha}";
my $save-to = $*CWD.child("backup_dir{$tag-or-sha}"); # must include tag in save path currently :/
my $saved-to = $git.fetch($source, $save-to);
say "Zef META6 from HEAD: ";
say $saved-to.child("META6.json").slurp;
# Extract the repository
my $extract-to = $*CWD.child("extracted_backup_dir");
my $extracted-to = $git.extract($saved-to, $extract-to);
say "Zef META6 from older $tag-or-sha: ";
say $extracted-to.dir.first({ .basename eq "META6.json" }).slurp;
Description
Fetcher
and Extractor
class for handling git URIs using the git
command.
You probably never want to use this unless its indirectly through Zef::Fetch
or Zef::Extractor
;
handling files and spawning processes will generally be easier using core language functionality. This
class exists to provide the means for cloning git repos and checking out revisions using the Fetcher
and Extractor
interfaces that the e.g. http/tar fetching/extracting adapters use.
Methods
method probe
method probe(--> Bool:D)
Returns True
if this module can successfully launch the git
command.
method fetch-matcher
method fetch-matcher(Str() $uri --> Bool:D)
Returns True
if this module knows how to fetch $uri
, which it decides based on if a parsed $uri
ends with .git
(including local directories) and starts with any of http
git
ssh
.
method extract-matcher
method extract-matcher(Str() $uri --> Bool:D)
Returns True
if this module knows how to extract $uri
, which it decides based on if a parsed $uri
looks like a directory and if git status
can successfully be run from that directory.
method fetch
method fetch(Str() $uri, IO() $save-to, Supplier :$stdout, Supplier :$stderr --> IO::Path)
Fetches the given $uri
via git clone $uri $save-to
, or via git pull
if $save-to
is an existing git repo.
A Supplier
can be supplied as :$stdout
and :$stderr
to receive any output.
On success it returns the IO::Path
where the data was actually saved to. On failure it returns Nil
.
method extract
method extract(IO() $repo-path, IO() $extract-to, Supplier :$stdout, Supplier :$stderr)
Extracts the given $repo-path
from the file system to $save-to
via git checkout ...
. A Supplier
can
be supplied as :$stdout
and :$stderr
to receive any output.
On success it returns the IO::Path
where the data was actually extracted to. On failure it returns Nil
.
method ls-files
method ls-files(IO() $repo-path --> Array[Str])
On success it returns an Array
of relative paths that are available to be extracted from $repo-path
.