Alien-Build-Git
view release on metacpan or search on metacpan
lib/Alien/Build/Plugin/Fetch/Git.pm view on Meta::CPAN
{
$tmp->host('');
}
else
{
$tmp->host('localhost');
}
if($url =~ s/#(.*)$//)
{
$tmp->fragment($1);
}
$tmp->path($url);
$url = $tmp;
}
my $exe = Alien::git->exe;
if(defined $url->fragment)
{
local $CWD = tempdir( CLEANUP => 1 );
my($tag) = $url->fragment;
$url->fragment(undef);
if(can_branch_clone())
{
$build->system('%{git}', 'clone', '--depth' => 1, '--branch', "$tag", "$url");
}
else
{
$build->system('%{git}', 'clone', "$url");
}
die "command failed" if $?;
my($dir) = path(".")->absolute->children;
if(can_branch_clone())
{
# do nothing
}
else
{
# mildly prefer the -C version as it will handle spaces in $dir.
if(can_minus_c())
{
$build->system('%{git}', -C => "$dir", 'checkout', $tag);
}
else
{
$build->system("cd $dir ; %{git} checkout $tag");
}
die "command failed" if $?;
}
return {
type => 'file',
filename => $dir->basename,
path => $dir->stringify,
protocol => $url->scheme,
};
}
else
{
$build->log("fetching tags from $url");
my($output, $error) = capture_merged {
$build->system('%{git}', 'ls-remote', '--tags', "$url");
$?;
};
if($error)
{
print $output;
die "command failed";
}
my @tags = sort
grep { defined $_ }
map { m{refs/tags/(.*)$} ? $1 : undef }
split /\n\r?/, $output;
return {
type => 'list',
list => [
map {
my $tag = $_;
my $url = $url->clone;
$url->fragment($tag);
my %h = (
filename => $tag,
url => "$url",
);
\%h;
} @tags
],
protocol => $url->scheme,
};
}
},
);
}
my $can_minus_c;
sub can_minus_c
{
unless(defined $can_minus_c)
{
require Alien::git;
my $tmp = path(tempdir( CLEANUP => 1));
my(undef, $ret) = capture_merged {
system(Alien::git->exe, -C => $tmp, 'init');
$?;
};
$can_minus_c = !! $? == 0 && -d $tmp->child('.git');
$tmp->remove_tree;
}
$can_minus_c;
}
my $can_branch_clone;
sub can_branch_clone
{
unless(defined $can_branch_clone)
{
require Alien::git;
if(version_cmp(Alien::git->version, "1.8.3.5") >= 0)
{
$can_branch_clone = 1;
}
( run in 2.242 seconds using v1.01-cache-2.11-cpan-13bb782fe5a )