Skip to content

Instantly share code, notes, and snippets.

@mlask
Last active May 23, 2017 13:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mlask/6954a8f5f8525193379ac51f2d930432 to your computer and use it in GitHub Desktop.
SVN repository quick sync script
#!/usr/bin/php
<?php
$status = shell_exec('svn status --non-interactive');
if (strlen(trim($status)) > 0)
{
$status = explode("\n", trim($status));
echo("Syncing repository...\n");
foreach ($status as $item)
{
if (preg_match('/^\?\s+(.*)(?<!CVS\/Entries\.Log)$/', $item, $match))
echo(shell_exec('svn add ' . svn_esc($match[1])));
elseif (preg_match('/^\!\s+(.*)(?<!CVS\/Entries\.Log)$/', $item, $match))
echo(shell_exec('svn rm ' . svn_esc($match[1])));
elseif (preg_match('/^\!M\s+(.*)(?<!CVS\/Entries\.Log)$/', $item, $match))
echo(shell_exec('svn rm --force ' . svn_esc($match[1])));
elseif (preg_match('/^\?\s+(.*CVS\/Entries\.Log)$/', $item, $match))
echo(shell_exec('rm ' . escapeshellarg($match[1])));
}
}
else
echo("Nothing to sync.\n");
function svn_esc ($name)
{
if (strpos($name, '@') !== false)
$name .= '@';
return escapeshellarg($name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment