Last active
April 27, 2016 15:50
-
-
Save chrisbliss18/4531354 to your computer and use it in GitHub Desktop.
Recursively init and update submodules in a Git repo.
This file contains 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 | |
use strict; | |
use Cwd; | |
init_and_update(); | |
exit; | |
sub init_and_update | |
{ | |
my $start_path = cwd(); | |
my %paths; | |
my $updated; | |
do | |
{ | |
my $data = `find . -name '.gitmodules'`; | |
chomp($data); | |
$data =~ s/\/\.gitmodules//g; | |
foreach my $path (split(/\n/, $data)) | |
{ | |
if($paths{$path} eq '') | |
{ | |
$paths{$path} = ''; | |
} | |
} | |
$updated = 0; | |
foreach my $path (sort keys %paths) | |
{ | |
if($paths{$path} eq '') | |
{ | |
chdir($path); | |
`git submodule init 2>&1`; | |
`git submodule update 2>&1`; | |
`git submodule foreach 'git checkout master' 2>&1`; | |
`git submodule foreach 'git pull' 2>&1`; | |
chdir($start_path); | |
if($ARGV[0] eq '--remove-gitmodules') | |
{ | |
unlink("$path/.gitmodules"); | |
} | |
$paths{$path} = 1; | |
$updated++; | |
} | |
} | |
} while($updated); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment