Created
December 10, 2014 06:18
-
-
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.
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
<?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