Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for alternative SVN structures #1037

Merged
merged 3 commits into from

5 participants

@bboer

This feature adds basic support for the SvnDriver to work with a non-default directory structure.

By default most repositories are set-up with the trunk/branches/tags directories, however since Subversion does not enforce this (best-practice) structure it does happen that within companies the folder structure (slightly) differs from the best practice.

I added this pull request because (surprising) the company I work for uses a different structure which is a company policy to follow, so to be able to use composer (since I like it a lot) this feature could really make my life a lot better (and maybe others as well if they use a different structure).

Regards, Bart

@travisbot

This pull request passes (merged 93628c4 into e2f8098).

@Seldaek
Owner

Could you just change trunkLocation and others to trunk-path (or at least trunk-location)? I'm not sure if location or path is best, but we use dash separated words everywhere in composer.json, so it'd be best to follow that.

@Seldaek
Owner

Oh also I didn't realize you read it from the main Config instance, that's probably not a good idea because it makes the setting apply to all SVN repos. Ideally the VcsRepository should forward the whole $repoConfig array to VcsDrivers, so that you can get the data from there and configure it like:

{
    "repositories": [
        { "type": "svn", "url": "svn://..", "trunk-path": "boing" }
    ]
}

If you have no idea what I'm talking about, I guess I'll do the change myself while merging the PR :)

@bboer

Hi Seldaek, I'd like to try and implement it the way you are suggesting. To be able to forward the whole repoConfig would it be ok to add the repoConfig as an option to the VcsDriver constructor, or maybe as a parameter on the initialize method of the VcsDriver?

@Seldaek
Owner

@bboer I think the easiest would be to replace the $url arg of the constructor by the full repoConfig, otherwise you end up sending the url twice.

@bboer

Hi Seldaek, Just made some changes to pass the repoConfig through the constructor. It is indeed a nicer way to do it like this. Dit some tests locally with an alternative svn structure and it works nicely.

@Seldaek
Owner

Ok thanks, I'm leaving for a few days and will take a look at merging this when I get back, looks good though at first sight.

@travisbot

This pull request fails (merged d1a452b into e2f8098).

@stof

@bboer please fox the tests for the drivers

@travisbot

This pull request passes (merged 00361e0 into e2f8098).

@nfx

+1, the sooner the better :)

@Seldaek Seldaek merged commit 00361e0 into from
@Seldaek
Owner

Finally merged this, thanks. Also added docs http://getcomposer.org/doc/05-repositories.md#subversion-options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 29, 2012
  1. @bboer
Commits on Aug 30, 2012
  1. @bboer

    Made repoConfig available for the VcsDriver to be able to provide add…

    bboer authored
    …itional configuration options easily.
Commits on Aug 31, 2012
  1. @bboer

    Fixed tests

    bboer authored
This page is out of date. Refresh to see the latest.
View
2  src/Composer/Repository/Vcs/GitHubDriver.php
@@ -270,7 +270,7 @@ protected function fetchRootIdentifier()
// cannot ask for authentication credentials (because we
// are not interactive) then we fallback to GitDriver.
$this->gitDriver = new GitDriver(
- $this->generateSshUrl(),
+ array('url' => $this->generateSshUrl()),
$this->io,
$this->config,
$this->process,
View
33 src/Composer/Repository/Vcs/SvnDriver.php
@@ -32,6 +32,10 @@ class SvnDriver extends VcsDriver
protected $branches;
protected $infoCache = array();
+ protected $trunkPath = 'trunk';
+ protected $branchesPath = 'branches';
+ protected $tagsPath = 'tags';
+
/**
* @var \Composer\Util\Svn
*/
@@ -44,7 +48,17 @@ public function initialize()
{
$this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/');
- if (false !== ($pos = strrpos($this->url, '/trunk'))) {
+ if (isset($this->repoConfig['trunk-path'])) {
+ $this->trunkPath = $this->repoConfig['trunk-path'];
+ }
+ if (isset($this->repoConfig['branches-path'])) {
+ $this->branchesPath = $this->repoConfig['branches-path'];
+ }
+ if (isset($this->repoConfig['tags-path'])) {
+ $this->tagsPath = $this->repoConfig['tags-path'];
+ }
+
+ if (false !== ($pos = strrpos($this->url, '/' . $this->trunkPath))) {
$this->baseUrl = substr($this->url, 0, $pos);
}
@@ -59,7 +73,7 @@ public function initialize()
*/
public function getRootIdentifier()
{
- return 'trunk';
+ return $this->trunkPath;
}
/**
@@ -145,13 +159,14 @@ public function getTags()
if (null === $this->tags) {
$this->tags = array();
- $output = $this->execute('svn ls --verbose', $this->baseUrl . '/tags');
+ $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath);
if ($output) {
foreach ($this->process->splitLines($output) as $line) {
$line = trim($line);
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
- $this->tags[rtrim($match[2], '/')] = '/tags/'.$match[2].'@'.$match[1];
+ $this->tags[rtrim($match[2], '/')] = '/' . $this->tagsPath .
+ '/' . $match[2] . '@' . $match[1];
}
}
}
@@ -174,8 +189,9 @@ public function getBranches()
foreach ($this->process->splitLines($output) as $line) {
$line = trim($line);
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
- if (isset($match[1]) && isset($match[2]) && $match[2] === 'trunk/') {
- $this->branches['trunk'] = '/trunk/@'.$match[1];
+ if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkPath . '/') {
+ $this->branches[$this->trunkPath] = '/' . $this->trunkPath .
+ '/@'.$match[1];
break;
}
}
@@ -183,13 +199,14 @@ public function getBranches()
}
unset($output);
- $output = $this->execute('svn ls --verbose', $this->baseUrl . '/branches');
+ $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesPath);
if ($output) {
foreach ($this->process->splitLines(trim($output)) as $line) {
$line = trim($line);
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
- $this->branches[rtrim($match[2], '/')] = '/branches/'.$match[2].'@'.$match[1];
+ $this->branches[rtrim($match[2], '/')] = '/' . $this->branchesPath .
+ '/' . $match[2] . '@' . $match[1];
}
}
}
View
10 src/Composer/Repository/Vcs/VcsDriver.php
@@ -27,6 +27,7 @@
{
protected $url;
protected $originUrl;
+ protected $repoConfig;
protected $io;
protected $config;
protected $process;
@@ -35,16 +36,17 @@
/**
* Constructor.
*
- * @param string $url The URL
+ * @param array $repoConfig The repository configuration
* @param IOInterface $io The IO instance
* @param Config $config The composer configuration
* @param ProcessExecutor $process Process instance, injectable for mocking
* @param callable $remoteFilesystem Remote Filesystem, injectable for mocking
*/
- final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
+ final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
{
- $this->url = $url;
- $this->originUrl = $url;
+ $this->url = $repoConfig['url'];
+ $this->originUrl = $repoConfig['url'];
+ $this->repoConfig = $repoConfig;
$this->io = $io;
$this->config = $config;
$this->process = $process ?: new ProcessExecutor;
View
8 src/Composer/Repository/VcsRepository.php
@@ -33,6 +33,7 @@ class VcsRepository extends ArrayRepository
protected $versionParser;
protected $type;
protected $loader;
+ protected $repoConfig;
public function __construct(array $repoConfig, IOInterface $io, Config $config, array $drivers = null)
{
@@ -50,6 +51,7 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config,
$this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
$this->verbose = $io->isVerbose();
$this->config = $config;
+ $this->repoConfig = $repoConfig;
}
public function setLoader(LoaderInterface $loader)
@@ -61,7 +63,7 @@ public function getDriver()
{
if (isset($this->drivers[$this->type])) {
$class = $this->drivers[$this->type];
- $driver = new $class($this->url, $this->io, $this->config);
+ $driver = new $class($this->repoConfig, $this->io, $this->config);
$driver->initialize();
return $driver;
@@ -69,7 +71,7 @@ public function getDriver()
foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->url)) {
- $driver = new $driver($this->url, $this->io, $this->config);
+ $driver = new $driver($this->repoConfig, $this->io, $this->config);
$driver->initialize();
return $driver;
@@ -78,7 +80,7 @@ public function getDriver()
foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->url, true)) {
- $driver = new $driver($this->url, $this->io, $this->config);
+ $driver = new $driver($this->repoConfig, $this->io, $this->config);
$driver->initialize();
return $driver;
View
24 tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php
@@ -77,7 +77,11 @@ public function testPrivateRepository()
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
->will($this->returnValue('{"master_branch": "test_master"}'));
- $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem);
+ $repoConfig = array(
+ 'url' => $repoUrl,
+ );
+
+ $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@@ -125,7 +129,11 @@ public function testPublicRepository()
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
->will($this->returnValue('{"master_branch": "test_master"}'));
- $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem);
+ $repoConfig = array(
+ 'url' => $repoUrl,
+ );
+
+ $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@@ -183,7 +191,11 @@ public function testPublicRepository2()
->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer/packagist/commits/feature%2F3.2-foo'), $this->equalTo(false))
->will($this->returnValue('{"commit": {"committer":{ "date": "2012-09-10"}}}'));
- $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem);
+ $repoConfig = array(
+ 'url' => $repoUrl,
+ );
+
+ $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@@ -271,7 +283,11 @@ public function testPrivateRepositoryNoInteraction()
->method('splitLines')
->will($this->returnValue(array('* test_master')));
- $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem);
+ $repoConfig = array(
+ 'url' => $repoUrl,
+ );
+
+ $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
$gitHubDriver->initialize();
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
View
6 tests/Composer/Test/Repository/Vcs/SvnDriverTest.php
@@ -45,7 +45,11 @@ public function testWrongCredentialsInUrl()
'home' => sys_get_temp_dir() . '/composer-test',
),
));
- $svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, $config, $process);
+ $repoConfig = array(
+ 'url' => 'http://till:secret@corp.svn.local/repo',
+ );
+
+ $svn = new SvnDriver($repoConfig, $console, $config, $process);
$svn->initialize();
}
Something went wrong with that request. Please try again.