Skip to content

Instantly share code, notes, and snippets.

@averyaube
Created June 24, 2011 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averyaube/1044950 to your computer and use it in GitHub Desktop.
Save averyaube/1044950 to your computer and use it in GitHub Desktop.
Tiny PHP svn script
<?php
/**
* Some cool thing that does various little SVN tasks.
* Requires the PECL svn package to be installed!
*
* @author Lowgain / BNOTIONS
*/
// Define some cool parameters here
define('USERNAME', '');
define('PASSWORD', '');
define('DOCROOT', dirname(__FILE__));
// Set subversion credentials
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, USERNAME);
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, PASSWORD);
// Can optionally set a revision number
$revision = isset($_GET['rev']) ? $_GET['rev'] : SVN_REVISION_HEAD;
// Action can be defined via GET var
$action = isset($_GET['action']) ? $_GET['action'] : 'update';
// Try to run the defined action
if (function_exists($action))
{
$action();
}
else
{
die('Invalid action!!!! :-(');
}
/**
* Update the defined docroot to the defined revision!
*
* @return void
*/
function update()
{
if ($rev = svn_update(DOCROOT, $revision, TRUE))
{
echo "Updated to revision {$rev}!";
}
else
{
// Doesn't seem to be any functionality to
// display what TYPE of error occurred
echo "Some kind of error";
}
}
/**
* Revert any non-versioned changed in the docroot
*
* @return void
*/
function revert()
{
if (svn_revert(DOCROOT, TRUE))
{
echo "All changed reverted.";
}
else
{
echo "Error reverting? :-(";
}
}
/**
* Shows you the status of the repo
*
* @return void
*/
function status()
{
// TODO: Make this a little nicer
print_r(svn_status(DOCROOT));
}
/**
* Gives you a list of all commit logs. Warning can be huge
*
* @return void
*/
function logs()
{
print_r(svn_log());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment