Skip to content

Instantly share code, notes, and snippets.

@Gerjo
Created October 28, 2012 20:08
Show Gist options
  • Save Gerjo/3969711 to your computer and use it in GitHub Desktop.
Save Gerjo/3969711 to your computer and use it in GitHub Desktop.
Git pull all, a script that forks mutliple 'git submodule pull' actions. Much faster than "--recurse-submodules".
#!/usr/bin/php
<?php
$path = trim(`pwd`);
$submodulePath = $path . DIRECTORY_SEPARATOR . ".gitmodules";
$commands = array("cd {$path} && git pull");
if(is_file($submodulePath)) {
$ini = parse_ini_file($submodulePath, true);
if(count($ini) > 0) {
foreach($ini as $module) {
$pullPath = $path . DIRECTORY_SEPARATOR . $module["path"];
$commands[] = "cd {$pullPath} && git pull";
}
}
}
$pids = array();
foreach($commands as $cmd) {
$pid = pcntl_fork();
if($pid > 0) {
$pids[] = $pid;
continue;
} else if($pid == 0) {
run($cmd);
exit;
} else {
exit("Unable to fork.");
}
}
print "Forked " . count($pids) . " job" . ($pids != 1 ? 's' : '') . ". Waiting for completion:" . PHP_EOL;
foreach($pids as $pid) {
pcntl_wait($pid);
}
function run($command) {
ob_start();
echo $command . PHP_EOL;
$out = exec($command);
echo $out . PHP_EOL . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment