Skip to content

Instantly share code, notes, and snippets.

@tsucchi
Created June 6, 2013 07:58
Show Gist options
  • Select an option

  • Save tsucchi/5719989 to your computer and use it in GitHub Desktop.

Select an option

Save tsucchi/5719989 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# 複数リポジトリをまとめて pull する君
use strict;
use warnings;
use List::MoreUtils qw(first_value);
use Cwd;
use File::Spec;
opendir my $dir, '.' or die "can't open dir : $!";
my @modules = grep { $_ !~ qr/^\.(:?\.)?/ } readdir $dir;
closedir $dir or die "can't close dir : $!";
for my $module_name ( @modules ) {
my $cwd = getcwd();
next if ( !-d File::Spec->catdir($cwd, $module_name) );
chdir $module_name or die "can't chdir to $module_name : $!";
if( -d File::Spec->catdir($cwd, $module_name, ".git") ) {
print "$module_name : ";
execute_git_pull();
}
chdir $cwd or die "failed to chdir $cwd : $!";
}
sub execute_git_pull {
my $current_branch = current_branch_name();
if ( $current_branch eq 'master' ) {
system("git pull") and die "git pull failed: $!";
}
else {
print "$current_branch is not master, skip pulling...\n";
}
}
sub current_branch_name {
my @branches = `git branch`;
chomp(@branches);
my $current_branch = first_value { $_ =~ qr/^\*/ } @branches;
$current_branch =~ s/^\*\s+//;
return $current_branch;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment