Skip to content

Commit

Permalink
Add a way to specify a particular commit in URLs
Browse files Browse the repository at this point in the history
Since the HEAD of a repo may be where development happens and a
particular tag or commit will correspond to a particular version of a
module, allow URLS of the form  git://github.com/foo/bar@v1.2.3
to checkout the commit specified by "v1.2.3" once the repo is cloned.
  • Loading branch information
perlpilot committed Jan 23, 2015
1 parent a4fc9ac commit ac1ba34
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Panda/Fetcher.pm
Expand Up @@ -4,16 +4,18 @@ use Shell::Command;

method fetch($from, $to) {
given $from {
my $commit;
$from.=subst(/ '@' (<[ . / ]+alpha+digit>+) $/, { $commit = $0; "" });
when /\.git$/ {
return git-fetch $from, $to;
return git-fetch $from, $to, $commit;
}
when /^ $<schema>=[<alnum><[+.-]+alnum>*] '://' / {
when $<schema> {
when /^'git://'/ {
return git-fetch $from, $to;
return git-fetch $from, $to, $commit;
}
when /^[http|https]'+git://'/ {
return git-fetch $from.subst(/'+git'/, ''), $to;
return git-fetch $from.subst(/'+git'/, ''), $to, $commit;
}
when /^'file://'/ {
return local-fetch $from.subst(/^'file://'/, ''), $to;
Expand All @@ -34,9 +36,13 @@ method fetch($from, $to) {
return True;
}

sub git-fetch($from, $to) {
sub git-fetch($from, $to, $commit = Nil) {
shell "git clone -q $from \"$to\""
or fail "Failed cloning git repository '$from'";
if $commit {
temp $*CWD = chdir($to);
shell "git checkout $commit";
}
return True;
}

Expand Down

0 comments on commit ac1ba34

Please sign in to comment.