Skip to content

Instantly share code, notes, and snippets.

@Lowgain
Created Jun 24, 2011
Embed
What would you like to do?
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