Skip to content

Commit

Permalink
refactored skip update, fixes duplicated local copies and local paths…
Browse files Browse the repository at this point in the history
… in .lock file
  • Loading branch information
schmunk42 committed Mar 29, 2017
1 parent 1da0bc0 commit f0b09de
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions Repository/Vcs/GitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Composer\Cache;
use Composer\IO\IOInterface;
use Composer\Repository\Vcs\GitDriver as BaseGitDriver;
use Composer\Util\Filesystem;
use Composer\Util\Git as GitUtil;

/**
* Git vcs driver.
Expand Down Expand Up @@ -45,17 +47,49 @@ public function initialize()
/* @var AssetRepositoryManager $arm */
$arm = $this->repoConfig['asset-repository-manager'];

$skipSync = false;
if (null !== ($skip = $arm->getConfig()->get('git-skip-update'))) {
$localUrl = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';

// check if local copy exists and if it is a git repository and that modification time is within threshold
if (is_dir($localUrl) && is_file($localUrl.'/config') && filemtime($localUrl) > strtotime('-'.$skip)) {
$this->io->write('(<comment>local</comment>) ', false, IOInterface::VERBOSE);
$this->url = $localUrl;
} else {
$this->io->write('(<info>remote</info>) ', false, IOInterface::VERBOSE);
$skipSync = true;
$this->io->write('(<comment>skip update</comment>) ', false, IOInterface::VERBOSE);
}
}

// copied from parent::initialize()
if (Filesystem::isLocalPath($this->url)) {
$this->url = preg_replace('{[\\/]\.git/?$}', '', $this->url);
$this->repoDir = $this->url;
$cacheUrl = realpath($this->url);
} else {
$this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';

GitUtil::cleanEnv();

$fs = new Filesystem();
$fs->ensureDirectoryExists(dirname($this->repoDir));

if (!is_writable(dirname($this->repoDir))) {
throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.dirname($this->repoDir).'" directory is not writable by the current user.');
}

if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
throw new \InvalidArgumentException('The source URL '.$this->url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
}

$gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
// patched line, sync from local dir without modifying url
if (!$skipSync && !$gitUtil->syncMirror($this->url, $this->repoDir)) {
$this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated</error>');
}

$cacheUrl = $this->url;
}
parent::initialize();

$this->getTags();
$this->getBranches();

$this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl));
}
}

0 comments on commit f0b09de

Please sign in to comment.