Created
August 3, 2011 14:48
-
-
Save thinkt4nk/1122804 to your computer and use it in GitHub Desktop.
Remove svn traces from directory structure
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 | |
/** | |
* Script to recursively remove all traces of svn from a directory tree | |
* Author: Ryan Bales, Creative Anvil 2011 | |
*/ | |
ini_set('memory_limit','512M'); | |
function usage() | |
{ | |
ob_start(); ?> | |
::UnSvn:: | |
Script to recursively remove all traces of svn from a directory tree | |
Usage: /path/to/php unsvn.php /path/to/directory | |
<?php echo ob_get_clean(); | |
} | |
function rrmdir($dir) { | |
if (is_dir($dir)) { | |
$objects = scandir($dir); | |
foreach ($objects as $object) { | |
if ($object != "." && $object != "..") { | |
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); | |
} | |
} | |
reset($objects); | |
rmdir($dir); | |
} | |
} | |
function unsvn($files) | |
{ | |
foreach( $files as $file ) { | |
$filename = str_replace(dirname($file),'',$file); | |
if( $filename == '/.' || $filename == '/..' ) { | |
continue; | |
} elseif ( $filename == '/.svn' && is_dir($file) ) { | |
echo "deleting file {$file}\n"; | |
rrmdir($file); | |
} else { | |
if( is_dir($file) ) { | |
// recurse | |
$inner_files = scandir($file); | |
$dirname = $file; | |
$filepaths = array(); | |
foreach( $inner_files as $inner_file ) { | |
$filepaths[] = "{$dirname}/{$inner_file}"; | |
} | |
unsvn($filepaths); | |
} | |
} | |
} | |
} | |
if( count($argv) > 1 ) { | |
if( is_dir($argv[1]) ) { | |
unsvn(array($argv[1])); | |
} else { | |
usage(); | |
} | |
} else { | |
usage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment