Skip to content

Instantly share code, notes, and snippets.

@SamuelDavis
Created December 10, 2014 06:18
Show Gist options
  • Save SamuelDavis/30c49d0e1f8435876484 to your computer and use it in GitHub Desktop.
Save SamuelDavis/30c49d0e1f8435876484 to your computer and use it in GitHub Desktop.
Parses a .gitmodules file (named 'gitmodules') and runs git submodule add for every submodule in the file.
<?php
$submodules = array_filter(explode("\n", file_get_contents('./gitmodules')));
for($i = 0; $i < count($submodules); $i += 3) {
$path = str_replace('path = ', '', trim($submodules[$i + 1]));
$url = str_replace('url = ', '', trim($submodules[$i + 2]));
if($path && $url) {
$path = "./$path";
$pathParentParts = explode('/', $path);
$pathParent = implode('/', array_slice($pathParentParts, 0, count($pathParentParts) - 1));
if(!is_dir($pathParent)) {
mkdir($pathParent, '0777', TRUE);
}
$cmd = "git submodule add $url $path";
echo $cmd . "\n";
shell_exec($cmd);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment