Created
January 27, 2009 10:54
-
-
Save typester/53293 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Cwd; | |
use File::chdir; | |
use Path::Class qw/dir/; | |
use WWW::Mechanize; | |
use Getopt::Long; | |
GetOptions( | |
\my %opt, | |
qw/private anonymous/ | |
); | |
my $cwd = dir($ARGV[0] || getcwd); | |
my $github = do { | |
local $CWD = $cwd; | |
{ | |
login => qx{ git config github.user }, | |
token => qx{ git config github.token }, | |
}; | |
}; | |
die "required git config github.user & github.token" | |
unless $github->{login} && $github->{token}; | |
chomp($github->{login}, $github->{token}); | |
my $mech = WWW::Mechanize->new( stack_depth => 1 ); | |
$mech->get('http://gist.github.com'); | |
die $mech->status unless $mech->success; | |
my $i = 0; | |
my $data = {}; | |
$cwd->recurse( callback => sub { | |
my $f = shift; | |
return unless -f $f; | |
(my $name = $f) =~ s!^$cwd/!!; | |
return if $name =~ m!^\.git($|/)!; | |
my $index = 'gistfile' . ++$i; | |
$data->{"file_name[${index}]"} = $name; | |
$data->{"file_contents[${index}]"} = $f->slurp; | |
}); | |
$mech->submit_form( | |
fields => { | |
%$data, | |
$opt{anonymous} ? () : (%$github), | |
}, | |
form_number => 2, | |
$opt{private} ? (button => 'action_button') : (), | |
); | |
die $mech->status unless $mech->success; | |
my ($repo) = $mech->content =~ m!(git\@gist\.github\.com:.+?.git)!; | |
die "can't find repository path" unless $repo; | |
{ | |
local $CWD = $cwd; | |
qx{ git remote add origin $repo }; | |
qx{ git pull origin master }; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment