Svn related coding style/consistency fixes and minor improvements
parent
da649fdc79
commit
8fb9c4bf3b
|
@ -68,7 +68,7 @@ class SvnDownloader extends VcsDownloader
|
||||||
*/
|
*/
|
||||||
protected function enforceCleanDirectory($path)
|
protected function enforceCleanDirectory($path)
|
||||||
{
|
{
|
||||||
$this->process->execute(sprintf('cd %s && svn status', escapeshellarg($path)), $output);
|
$this->process->execute('svn status', $output, $path);
|
||||||
if (trim($output)) {
|
if (trim($output)) {
|
||||||
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes');
|
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes');
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,6 @@ class SvnDownloader extends VcsDownloader
|
||||||
}
|
}
|
||||||
|
|
||||||
// this could be any failure, since SVN exits with 1 always
|
// this could be any failure, since SVN exits with 1 always
|
||||||
|
|
||||||
if (empty($output)) {
|
if (empty($output)) {
|
||||||
$output = $this->process->getErrorOutput();
|
$output = $this->process->getErrorOutput();
|
||||||
}
|
}
|
||||||
|
@ -100,7 +99,7 @@ class SvnDownloader extends VcsDownloader
|
||||||
}
|
}
|
||||||
|
|
||||||
// the error is not auth-related
|
// the error is not auth-related
|
||||||
if (false === strpos($output, 'authorization failed:')) {
|
if (false === stripos($output, 'authorization failed:')) {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,19 +113,17 @@ class SvnDownloader extends VcsDownloader
|
||||||
} else {
|
} else {
|
||||||
$this->io->write("Authorization failed: {$command}");
|
$this->io->write("Authorization failed: {$command}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is potentially heavy - recreating Util often.
|
|
||||||
*
|
|
||||||
* @param string $url
|
* @param string $url
|
||||||
*
|
*
|
||||||
* @return \Composer\Util\Svn
|
* @return \Composer\Util\Svn
|
||||||
*/
|
*/
|
||||||
protected function getUtil($url)
|
protected function getUtil($url)
|
||||||
{
|
{
|
||||||
$util = new SvnUtil($url, $this->io);
|
return new SvnUtil($url, $this->io);
|
||||||
return $util;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ class SvnDriver extends VcsDriver
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function execute($command, $url)
|
protected function execute($command, $url)
|
||||||
{
|
{
|
||||||
$svnCommand = $this->util->getCommand($command, $url);
|
$svnCommand = $this->util->getCommand($command, $url);
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class SvnDriver extends VcsDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
// the error is not auth-related
|
// the error is not auth-related
|
||||||
if (strpos($output, 'authorization failed:') === false) {
|
if (false === stripos($output, 'authorization failed:')) {
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,11 +281,13 @@ class SvnDriver extends VcsDriver
|
||||||
// This is definitely a Subversion repository.
|
// This is definitely a Subversion repository.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (preg_match('/authorization failed/i', $processExecutor->getErrorOutput())) {
|
|
||||||
|
if (false !== stripos($processExecutor->getErrorOutput(), 'authorization failed:')) {
|
||||||
// This is likely a remote Subversion repository that requires
|
// This is likely a remote Subversion repository that requires
|
||||||
// authentication. We will handle actual authentication later.
|
// authentication. We will handle actual authentication later.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,12 @@ use Composer\IO\IOInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Till Klampaeckel <till@php.net>
|
* @author Till Klampaeckel <till@php.net>
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*/
|
*/
|
||||||
class Svn
|
class Svn
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var mixed
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $credentials;
|
protected $credentials;
|
||||||
|
|
||||||
|
@ -40,10 +41,9 @@ class Svn
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache credentials.
|
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $useCache = false;
|
protected $cacheCredentials = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
@ -66,30 +66,14 @@ class Svn
|
||||||
{
|
{
|
||||||
$this->io->write("The Subversion server ({$this->url}) requested credentials:");
|
$this->io->write("The Subversion server ({$this->url}) requested credentials:");
|
||||||
|
|
||||||
$this->hasAuth = true;
|
$this->hasAuth = true;
|
||||||
$this->credentials = new \stdClass();
|
$this->credentials['username'] = $this->io->ask("Username: ");
|
||||||
|
$this->credentials['password'] = $this->io->askAndHideAnswer("Password: ");
|
||||||
|
|
||||||
$this->credentials->username = $this->io->ask("Username: ");
|
$this->cacheCredentials = $this->io->askConfirmation("Should Subversion cache these credentials? (yes/no) ", false);
|
||||||
$this->credentials->password = $this->io->askAndHideAnswer("Password: ");
|
|
||||||
|
|
||||||
$pleaseCache = $this->io->askConfirmation("Should Subversion cache these credentials? (yes/no) ", false);
|
|
||||||
if ($pleaseCache) {
|
|
||||||
$this->useCache = true;
|
|
||||||
}
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Return the no-auth-cache switch.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getAuthCache()
|
|
||||||
{
|
|
||||||
if (!$this->useCache) {
|
|
||||||
return '--no-auth-cache ';
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method to create the svn commands run.
|
* A method to create the svn commands run.
|
||||||
|
@ -100,7 +84,7 @@ class Svn
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCommand($cmd, $url, $path = '')
|
public function getCommand($cmd, $url, $path = null)
|
||||||
{
|
{
|
||||||
$cmd = sprintf('%s %s%s %s',
|
$cmd = sprintf('%s %s%s %s',
|
||||||
$cmd,
|
$cmd,
|
||||||
|
@ -108,7 +92,8 @@ class Svn
|
||||||
$this->getCredentialString(),
|
$this->getCredentialString(),
|
||||||
escapeshellarg($url)
|
escapeshellarg($url)
|
||||||
);
|
);
|
||||||
if (!empty($path)) {
|
|
||||||
|
if ($path) {
|
||||||
$cmd .= ' ' . escapeshellarg($path);
|
$cmd .= ' ' . escapeshellarg($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,16 +106,13 @@ class Svn
|
||||||
* Adds --no-auth-cache when credentials are present.
|
* Adds --no-auth-cache when credentials are present.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @uses self::$useAuth
|
|
||||||
*/
|
*/
|
||||||
public function getCredentialString()
|
public function getCredentialString()
|
||||||
{
|
{
|
||||||
if ($this->hasAuth === null) {
|
if (!$this->hasAuth()) {
|
||||||
$this->hasAuth();
|
|
||||||
}
|
|
||||||
if (!$this->hasAuth) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
' %s--username %s --password %s ',
|
' %s--username %s --password %s ',
|
||||||
$this->getAuthCache(),
|
$this->getAuthCache(),
|
||||||
|
@ -148,12 +130,10 @@ class Svn
|
||||||
public function getPassword()
|
public function getPassword()
|
||||||
{
|
{
|
||||||
if ($this->credentials === null) {
|
if ($this->credentials === null) {
|
||||||
throw new \LogicException("No auth detected.");
|
throw new \LogicException("No svn auth detected.");
|
||||||
}
|
}
|
||||||
if (isset($this->credentials->password)) {
|
|
||||||
return $this->credentials->password;
|
return isset($this->credentials['password']) ? $this->credentials['password'] : '';
|
||||||
}
|
|
||||||
return ''; // could be empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,9 +145,10 @@ class Svn
|
||||||
public function getUsername()
|
public function getUsername()
|
||||||
{
|
{
|
||||||
if ($this->credentials === null) {
|
if ($this->credentials === null) {
|
||||||
throw new \LogicException("No auth detected.");
|
throw new \LogicException("No svn auth detected.");
|
||||||
}
|
}
|
||||||
return $this->credentials->username;
|
|
||||||
|
return $this->credentials['username'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,29 +156,34 @@ class Svn
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public function hasAuth()
|
public function hasAuth()
|
||||||
{
|
{
|
||||||
if ($this->hasAuth !== null) {
|
if (null !== $this->hasAuth) {
|
||||||
return $this->hasAuth;
|
return $this->hasAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = parse_url($this->url);
|
$uri = parse_url($this->url);
|
||||||
if (empty($uri['user'])) {
|
if (empty($uri['user'])) {
|
||||||
$this->hasAuth = false;
|
return $this->hasAuth = false;
|
||||||
return $this->hasAuth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hasAuth = true;
|
$this->credentials['username'] = $uri['user'];
|
||||||
$this->credentials = new \stdClass();
|
|
||||||
|
|
||||||
$this->credentials->username = $uri['user'];
|
|
||||||
|
|
||||||
if (!empty($uri['pass'])) {
|
if (!empty($uri['pass'])) {
|
||||||
$this->credentials->password = $uri['pass'];
|
$this->credentials['password'] = $uri['pass'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->hasAuth;
|
return $this->hasAuth = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the no-auth-cache switch.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getAuthCache()
|
||||||
|
{
|
||||||
|
return $this->cacheCredentials ? '' : '--no-auth-cache ';
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,9 +15,6 @@ namespace Composer\Test\Repository\Vcs;
|
||||||
use Composer\Repository\Vcs\SvnDriver;
|
use Composer\Repository\Vcs\SvnDriver;
|
||||||
use Composer\IO\NullIO;
|
use Composer\IO\NullIO;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Till Klampaeckel <till@php.net>
|
|
||||||
*/
|
|
||||||
class SvnDriverTest extends \PHPUnit_Framework_TestCase
|
class SvnDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue