public
Created

  • Download Gist
git-fetch-branch
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use Git::Wrapper;
use Time::Piece;
 
my ( $remote_repo, $remote_branch ) = @ARGV;
 
die "Usage: $0 <remote_repo> <remote_branch>"
unless $remote_repo;
 
$remote_branch //= 'master';
 
my $local_branch;
 
if ( $remote_repo =~ m{github\.com/([^/]+)/} ) {
$local_branch = "review/$1-$remote_branch";
}
else {
my $time = localtime->datetime;
$time =~ tr[:][-];
$local_branch = "review/$time";
}
 
my $git = Git::Wrapper->new(".");
$git->fetch( $remote_repo, $remote_branch );
$git->branch( $local_branch, 'FETCH_HEAD' );
 
say "Fetched $remote_repo $remote_branch -> $local_branch";
 
# vim: ts=4 sts=4 sw=4 et:

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.