Created
November 7, 2011 10:26
-
-
Save aizatto/1344622 to your computer and use it in GitHub Desktop.
Migrate from Symfony deps to git sumbodules
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 | |
function run($command) { | |
echo $command."\n"; | |
$output = null; | |
$return_var = null; | |
exec($command, $ouput, $return_var); | |
echo $output; | |
if ($return_var != 0) { | |
exit($return_var); | |
} | |
} | |
$versions = array(); | |
$lines = explode("\n", file_get_contents('deps.lock')); | |
foreach ($lines as $line) { | |
list($project, $version) = explode(" ", $line); | |
$versions[$project] = $version; | |
} | |
$projects = parse_ini_file('deps', true); | |
foreach ($projects as $project => $config) { | |
if (!isset($config['git'])) { | |
continue; | |
} | |
$git = $config['git']; | |
if (isset($config['target'])) { | |
$target = $config['target']; | |
} else { | |
$target = $project; | |
} | |
if ($target[0] == '/') { | |
$target = substr($target, 1); | |
} | |
$target = "./vendor/$target"; | |
$version = $versions[$project]; | |
var_dump($target); | |
var_dump(file_exists($target)); | |
var_dump($version); | |
if (file_exists($target)) { | |
chdir($target); | |
run("git fetch"); | |
run("git checkout $version"); | |
chdir(__DIR__); | |
} else { | |
run("git submodule add $git $target"); | |
if (!isset($versions[$project])) { | |
continue; | |
} | |
chdir($target); | |
run("git checkout $version"); | |
chdir(__DIR__); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment