Created
July 19, 2011 15:04
-
-
Save chobie/1092690 to your computer and use it in GitHub Desktop.
chobie's git svn externals
This file contains hidden or 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/local/Cellar/php/5.3.6/bin/php | |
<?php | |
/* | |
git svn externals | |
git svn checkout-externals | |
git svn update-externals | |
git svn remove-externals | |
.externalsにデータはいれておく。 | |
*/ | |
interface GitCommand | |
{ | |
public function preExecute(); | |
public function onExecute(); | |
public function postExecute(); | |
} | |
class GitCommandStatus implements GitCommand | |
{ | |
public function preExecute() | |
{ | |
system("git status"); | |
echo PHP_EOL; | |
echo "# look into svn:externals..." . PHP_EOL; | |
} | |
public function onExecute() | |
{ | |
system("svn st"); | |
} | |
public function postExecute() | |
{ | |
} | |
} | |
//////////////////////////////////////////// | |
$argv = $_SERVER['argv']; | |
array_shift($argv); | |
$command = ""; | |
$commands = array( | |
"status" => "GitCommandStatus", | |
); | |
if(count($argv) == 0) { | |
echo "git svn-externals" .PHP_EOL; | |
exit; | |
} else { | |
switch($argv['0']) { | |
case "st": | |
case "status": | |
$command = "status"; | |
break; | |
case "up": | |
case "update": | |
$command = "update"; | |
case "co": | |
case "checkout": | |
break; | |
case "unlink": | |
break; | |
case "link": | |
break; | |
case "reload": | |
break; | |
default: | |
exit; | |
} | |
} | |
$top_dir = trim(`git rev-parse --show-cdup`); | |
$path = realpath($top_dir); | |
chdir($path); | |
if(!file_exists("{$path}/.git/externals")) { | |
mkdir("{$path}/.git/externals"); | |
} | |
if(!file_exists("{$path}/.git/info/externals")) { | |
$externals = trim(`git svn show-externals`); | |
file_put_contents("{$path}/.git/info/externals",$externals); | |
} else { | |
$externals = file_get_contents("{$path}/.git/info/externals"); | |
} | |
$lines = preg_split("/\r?\n/",$externals); | |
$fp = fopen($path . "/.git/info/exclude","a"); | |
$cn = $commands[$command]; | |
$class = new $cn(); | |
$class->preExecute(); | |
foreach ($lines as $line) { | |
$line = trim($line); | |
if($line == "" || strpos($line,"#") === 0) { | |
continue; | |
} | |
if (preg_match("/(?<path>.+?)\s(?<url>.+)/",$line,$match)) { | |
chdir($path); | |
$checkout = $match['path']; | |
$url = $match['url']; | |
$hash = sha1($url); | |
if(!is_link("{$path}/{$checkout}")) { | |
echo "svn co {$url} {$path}/.git/externals/{$hash}" . PHP_EOL; | |
system("svn co {$url} {$path}/.git/externals/{$hash}"); | |
system("ln -s {$path}/.git/externals/{$hash} {$path}{$checkout}"); | |
fwrite($fp, "# from chobi-git" . PHP_EOL); | |
fwrite($fp, "{$checkout}" . PHP_EOL); | |
} else { | |
if($command == "status") { | |
chdir("{$path}/.git/externals/{$hash}"); | |
echo "Performing status on external item at '{$checkout}'" . PHP_EOL; | |
$class->onExecute(); | |
echo PHP_EOL; | |
} else if($command == "update") { | |
chdir("{$path}/.git/externals/{$hash}"); | |
echo "updating {$checkout}..." . PHP_EOL; | |
system("svn up"); | |
} | |
} | |
} | |
} | |
fclose($fp); | |
$class->postExecute(); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment