Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 76 lines (57 sloc) 1.789 kb
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use Config::INI::Reader;
use Getopt::Long::Descriptive;
use JSON::XS;
{
package Git::Cloner::Source::Github;
use LWP::Simple qw(get);
sub repo_uris {
my $config = Config::INI::Reader->read_file("$ENV{HOME}/.gitconfig");
my $login = $config->{github}{login} || die "no github login\n";
my $token = $config->{github}{token} || die "no github token\n";
my $json =
get("http://github.com/api/v1/json/$login?login=$login&token=$token");
my $data = eval { JSON::XS->new->decode($json) };
die "BAD JSON\n$@\n$json\n" unless $data;
my @repos = @{ $data->{user}{repositories} };
my %repo_uri;
for my $repo (@repos) {
$repo_uri{ $repo->{name} } = sprintf 'git@github.com:%s/%s.git',
$login,
$repo;
}
return \%repo_uri;
}
}
my ($opt, $usage) = describe_options(
'%c %o',
# [ 'private|p!', 'include private repositories' ],
[ 'bare|b!', 'produce bare clones' ],
[ 'clonely|c', 'only clone things that do not exist; skip others' ],
);
my $repos = Git::Cloner::Source::Github->repo_uris;
my %existing_dir = map { $_ => 1 } grep { $_ !~ m{\A\.} and -d $_ } <*>;
for my $name (sort { $a cmp $b } keys %$repos) {
# next if $repo->{private} and not $opt->{private};
my $name = $name;
my $uri = $repos->{ $name };
if (-d $name) {
do_cmd("cd $name && git fetch origin && git merge origin/master 2>&1")
unless $opt->{clonely};
} else {
my $bare = $opt->{bare} ? '--bare' : '';
do_cmd("git clone $bare $uri 2>&1");
}
delete $existing_dir{ $name };
}
for (keys %existing_dir) {
warn "unknown directory found: $_\n";
}
sub do_cmd {
my ($cmd) = @_;
print "$cmd\n";
print `$cmd`;
}
Jump to Line
Something went wrong with that request. Please try again.