Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from niels-nijens/fix-subversion-adapter
Browse files Browse the repository at this point in the history
Fix subversion adapter
  • Loading branch information
niels-nijens committed May 31, 2016
2 parents 116a704 + 52fbe6d commit b0c1a4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
22 changes: 14 additions & 8 deletions src/Adapter/SubversionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*/
class SubversionAdapter extends AbstractAdapter
{
/**
* The regular expression to filter revision number and branch / tag name.
*
* @var string
*/
const BRANCHES_TAGS_REGEX = '#^(?:\s+)?(\d+).*\s(\S+)\/$#';

/**
* The path in the repository representing 'trunk' or 'master'.
*
Expand Down Expand Up @@ -61,21 +68,21 @@ public function getBranches()
{
$branches = array();

$result = $this->processExecutor->execute(sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument($this->repositoryUrl.'/'.$this->trunkPath)));
$result = $this->processExecutor->execute(sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument($this->repositoryUrl.'/'.$this->trunkPath)));
if ($result->isSuccessful()) {
foreach ($result->getOutputAsArray() as $branch) {
$matches = array();
if (preg_match('#^\s*(\S+).*?(\S+)\s*$#', $branch, $matches) && $matches[2] === './') {
if (preg_match(self::BRANCHES_TAGS_REGEX, $branch, $matches) === 1 && $matches[2] === '.') {
$branches[$matches[1]] = 'master';
}
}
}

$result = $this->processExecutor->execute(sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument($this->repositoryUrl.'/'.$this->branchesPath)));
$result = $this->processExecutor->execute(sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument($this->repositoryUrl.'/'.$this->branchesPath)));
if ($result->isSuccessful()) {
foreach ($result->getOutputAsArray() as $branch) {
$matches = array();
if (preg_match('#^\s*(\S+).*?(\S+)\s*$#', $branch, $matches)) {
if (preg_match(self::BRANCHES_TAGS_REGEX, $branch, $matches) === 1) {
$branches[$matches[1]] = $matches[2];
}
}
Expand All @@ -91,11 +98,11 @@ public function getTags()
{
$tags = array();

$result = $this->processExecutor->execute(sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument($this->repositoryUrl.'/'.$this->tagsPath)));
$result = $this->processExecutor->execute(sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument($this->repositoryUrl.'/'.$this->tagsPath)));
if ($result->isSuccessful()) {
foreach ($result->getOutputAsArray() as $tag) {
$matches = array();
if (preg_match('#^\s*(\S+).*?(\S+)\s*$#', $tag, $matches)) {
if (preg_match(self::BRANCHES_TAGS_REGEX, $tag, $matches) === 1) {
$tags[$matches[1]] = $matches[2];
}
}
Expand All @@ -121,8 +128,7 @@ public function checkout($version)
} else {
$escapedRepositoryDirectory = ProcessUtils::escapeArgument($this->repositoryDirectory);

$result = $this->processExecutor->execute(sprintf('svn checkout --non-interactive %s %s', $escapedRepositoryUrlWithVersionPath, $escapedRepositoryDirectory));
$checkoutSuccesful = $result->isSuccessful();
$checkoutSuccesful = $this->processExecutor->execute(sprintf('svn checkout --non-interactive %s %s', $escapedRepositoryUrlWithVersionPath, $escapedRepositoryDirectory))->isSuccessful();
}

return $checkoutSuccesful;
Expand Down
36 changes: 18 additions & 18 deletions tests/Adapter/SubversionAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public function provideTestSupportsRepository()
*/
public function provideTestGetBranches()
{
$trunkCommand = sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/trunk'));
$branchesCommand = sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/branches'));
$trunkCommand = sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/trunk'));
$branchesCommand = sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/branches'));

$provideTest = array();

Expand All @@ -179,7 +179,7 @@ public function provideTestGetBranches()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(1, '', ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", '')
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", '')
);
$provideTest[] = array($processExecutorMock, array('35' => '1.0'));

Expand All @@ -193,7 +193,7 @@ public function provideTestGetBranches()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", '')
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", '')
);
$provideTest[] = array($processExecutorMock, array('34' => 'master', '35' => '1.0'));

Expand All @@ -207,7 +207,7 @@ public function provideTestGetBranches()
*/
public function provideTestGetTags()
{
$tagsCommand = sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/tags'));
$tagsCommand = sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/tags'));

$provideTest = array();

Expand All @@ -224,7 +224,7 @@ public function provideTestGetTags()
$processExecutorMock->expects($this->once())
->method('execute')
->with($this->equalTo($tagsCommand))
->willReturn(new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''));
->willReturn(new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0/\n", ''));
$provideTest[] = array($processExecutorMock, array('35' => '0.1.0'));

return $provideTest;
Expand All @@ -237,9 +237,9 @@ public function provideTestGetTags()
*/
public function provideTestCheckout()
{
$getTrunkCommand = sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/trunk'));
$getBranchesCommand = sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/branches'));
$getTagsCommand = sprintf('svn ls --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/tags'));
$getTrunkCommand = sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/trunk'));
$getBranchesCommand = sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/branches'));
$getTagsCommand = sprintf('svn ls --non-interactive --verbose %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/tags'));
$infoCommand = 'svn info --non-interactive';
$trunkSwitchCommand = sprintf('svn switch --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/trunk'));
$branchSwitchCommand = sprintf('svn switch --non-interactive %s', ProcessUtils::escapeArgument('https://github.com/accompli/chrono/branches/1.0'));
Expand Down Expand Up @@ -284,8 +284,8 @@ public function provideTestCheckout()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0/\n", ''),
new ProcessExecutionResult(1, '', '')
);
$provideTest[] = array($processExecutorMock, false);
Expand All @@ -306,8 +306,8 @@ public function provideTestCheckout()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0/\n", ''),
new ProcessExecutionResult(0, '', '')
);
$provideTest[] = array($processExecutorMock, true);
Expand Down Expand Up @@ -349,8 +349,8 @@ public function provideTestCheckout()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0/\n", ''),
new ProcessExecutionResult(0, '', ''),
new ProcessExecutionResult(1, '', '')
);
Expand All @@ -373,8 +373,8 @@ public function provideTestCheckout()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0/\n", ''),
new ProcessExecutionResult(0, '', ''),
new ProcessExecutionResult(0, '', '')
);
Expand Down Expand Up @@ -414,7 +414,7 @@ public function provideTestCheckout()
)
->willReturnOnConsecutiveCalls(
new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''),
new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0/\n", ''),
new ProcessExecutionResult(0, '', ''),
new ProcessExecutionResult(0, '', '')
);
Expand Down

0 comments on commit b0c1a4d

Please sign in to comment.