Created
June 6, 2013 07:58
-
-
Save tsucchi/5719989 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/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