1
0
Fork 0

Teach FossilDriver to work with urls pointing to local repository.fossil files, and not just the local checkout directories.

pull/6608/head
kthbit 2017-08-12 11:31:57 -05:00
parent 72a66ad9d2
commit 927d3dda89
1 changed files with 62 additions and 42 deletions

View File

@ -34,12 +34,43 @@ class FossilDriver extends VcsDriver
*/ */
public function initialize() public function initialize()
{ {
if (Filesystem::isLocalPath($this->url)) { // Make sure fossil is installed and reachable.
$this->checkFossil();
// Ensure we are allowed to use this URL by config.
$this->config->prohibitUrlByConfig($this->url, $this->io);
// Only if url points to a locally accessible directory, assume it's the checkout directory.
// Otherwise, it should be something fossil can clone from.
if (Filesystem::isLocalPath($this->url) && is_dir($this->url)) {
$this->checkoutDir = $this->url; $this->checkoutDir = $this->url;
} else { } else {
$this->repoFile = $this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '.fossil'; $localName = preg_replace('{[^a-z0-9]}i', '-', $this->url);
$this->checkoutDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/'; $this->repoFile = $this->config->get('cache-repo-dir') . '/' . $localName . '.fossil';
$this->checkoutDir = $this->config->get('cache-vcs-dir') . '/' . $localName . '/';
}
$this->updateLocalRepo();
$this->getTags();
$this->getBranches();
}
/**
* Check that fossil can be invoked via command line.
*/
protected function checkFossil()
{
if (0 !== $this->process->execute('fossil version', $ignoredOutput)) {
throw new \RuntimeException("fossil was not found, check that it is installed and in your PATH env.\n\n" . $this->process->getErrorOutput());
}
}
/**
* Clone or update existing local fossil repository.
*/
protected function updateLocalRepo()
{
$fs = new Filesystem(); $fs = new Filesystem();
$fs->ensureDirectoryExists($this->checkoutDir); $fs->ensureDirectoryExists($this->checkoutDir);
@ -47,9 +78,6 @@ class FossilDriver extends VcsDriver
throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.$this->checkoutDir.'" directory is not writable by the current user.'); throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.$this->checkoutDir.'" directory is not writable by the current user.');
} }
// Ensure we are allowed to use this URL by config
$this->config->prohibitUrlByConfig($this->url, $this->io);
// update the repo if it is a valid fossil repository // update the repo if it is a valid fossil repository
if (is_file($this->repoFile) && is_dir($this->checkoutDir) && 0 === $this->process->execute('fossil info', $output, $this->checkoutDir)) { if (is_file($this->repoFile) && is_dir($this->checkoutDir) && 0 === $this->process->execute('fossil info', $output, $this->checkoutDir)) {
if (0 !== $this->process->execute('fossil pull', $output, $this->checkoutDir)) { if (0 !== $this->process->execute('fossil pull', $output, $this->checkoutDir)) {
@ -65,10 +93,6 @@ class FossilDriver extends VcsDriver
if (0 !== $this->process->execute(sprintf('fossil clone %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoFile)), $output)) { if (0 !== $this->process->execute(sprintf('fossil clone %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoFile)), $output)) {
$output = $this->process->getErrorOutput(); $output = $this->process->getErrorOutput();
if (0 !== $this->process->execute('fossil version', $ignoredOutput)) {
throw new \RuntimeException('Failed to clone '.$this->url.', fossil was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
}
throw new \RuntimeException('Failed to clone '.$this->url.' to repository ' . $this->repoFile . "\n\n" .$output); throw new \RuntimeException('Failed to clone '.$this->url.' to repository ' . $this->repoFile . "\n\n" .$output);
} }
@ -80,10 +104,6 @@ class FossilDriver extends VcsDriver
} }
} }
$this->getTags();
$this->getBranches();
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */