-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
584a164
commit dd559b0
Showing
2 changed files
with
67 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use Composer\Repository\Vcs\GitDriver as BaseGitDriver; | ||
use Composer\Util\Filesystem; | ||
use Composer\Util\Git as GitUtil; | ||
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager; | ||
|
||
/** | ||
* Git vcs driver. | ||
|
@@ -46,8 +47,8 @@ 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 | ||
|
@@ -57,39 +58,56 @@ public function initialize() | |
} | ||
} | ||
|
||
// 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) . '/'; | ||
$cacheUrl = Filesystem::isLocalPath($this->url) | ||
? $this->initializeLocalPath() : $this->initializeRemotePath($skipSync); | ||
$this->getTags(); | ||
$this->getBranches(); | ||
$this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl)); | ||
} | ||
|
||
GitUtil::cleanEnv(); | ||
/** | ||
* Initialize the local path. | ||
* | ||
* @return string | ||
*/ | ||
private function initializeLocalPath() | ||
{ | ||
$this->url = preg_replace('{[\\/]\.git/?$}', '', $this->url); | ||
$this->repoDir = $this->url; | ||
|
||
$fs = new Filesystem(); | ||
$fs->ensureDirectoryExists(dirname($this->repoDir)); | ||
return realpath($this->url); | ||
} | ||
|
||
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.'); | ||
} | ||
/** | ||
* Initialize the remote path. | ||
* | ||
* @param bool $skipSync Check if sync must be skipped | ||
* | ||
* @return string | ||
*/ | ||
private function initializeRemotePath($skipSync) | ||
{ | ||
$this->repoDir = $this->config->get('cache-vcs-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url).'/'; | ||
|
||
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://[email protected]:22/path or just [email protected]:path if you do not want to provide a password or custom port.'); | ||
} | ||
GitUtil::cleanEnv(); | ||
|
||
$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>'); | ||
} | ||
$fs = new Filesystem(); | ||
$fs->ensureDirectoryExists(dirname($this->repoDir)); | ||
|
||
$cacheUrl = $this->url; | ||
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.'); | ||
} | ||
|
||
$this->getTags(); | ||
$this->getBranches(); | ||
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://[email protected]:22/path or just [email protected]:path if you do not want to provide a password or custom port.'); | ||
} | ||
|
||
$this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl)); | ||
$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>'); | ||
} | ||
|
||
return $this->url; | ||
} | ||
} |