Last active
December 26, 2015 18:58
-
-
Save gena01/7197797 to your computer and use it in GitHub Desktop.
Composer conflict attempt
This file contains hidden or 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
diff --git a/doc/04-schema.md b/doc/04-schema.md | |
index ec885bf..c4de651 100644 | |
--- a/doc/04-schema.md | |
+++ b/doc/04-schema.md | |
@@ -655,6 +655,8 @@ The following options are supported: | |
* **prepend-autoloader:** Defaults to `true`. If false, the composer autoloader | |
will not be prepended to existing autoloaders. This is sometimesrequired to fix | |
interoperability issues with other autoloaders. | |
+* **github-domains:** Defaults to `["github.com"]`. A list of domains to use in | |
+ github mode. This is used for GitHub Enterprise setups. | |
* **notify-on-install:** Defaults to `true`. Composer allows repositories to | |
define a notification URL, so that they get notified whenever a package from | |
that repository is installed. This option allows you to disable that behaviour. | |
diff --git a/res/composer-schema.json b/res/composer-schema.json | |
index 1f68c8b..7b52d77 100644 | |
--- a/res/composer-schema.json | |
+++ b/res/composer-schema.json | |
@@ -179,6 +179,13 @@ | |
"prepend-autoloader": { | |
"type": "boolean", | |
"description": "If false, the composer autoloader will not be prepended to existing autoloaders, defaults to true." | |
+ }, | |
+ "github-domains": { | |
+ "type": "array", | |
+ "description": "A list of domains to use in github mode. This is used for GitHub Enterprise setups, defaults to [\"github.com\"].", | |
+ "items": { | |
+ "type": "string" | |
+ } | |
} | |
} | |
}, | |
diff --git a/src/Composer/Config.php b/src/Composer/Config.php | |
index 6151b4f..c893091 100644 | |
--- a/src/Composer/Config.php | |
+++ b/src/Composer/Config.php | |
@@ -36,6 +36,7 @@ class Config | |
'cache-files-maxsize' => '300MiB', | |
'discard-changes' => false, | |
'prepend-autoloader' => true, | |
+ 'github-domains' => array('github.com'), | |
); | |
public static $defaultRepositories = array( | |
diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php | |
index f320cf9..c8e5744 100644 | |
--- a/src/Composer/Downloader/GitDownloader.php | |
+++ b/src/Composer/Downloader/GitDownloader.php | |
@@ -293,7 +293,7 @@ class GitDownloader extends VcsDownloader | |
} | |
// public github, autoswitch protocols | |
- if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) { | |
+ if (preg_match('{^(?:https?|git)(://'.$this->getGitHubDomainsRegex().'/.*)}', $url, $match)) { | |
$protocols = $this->config->get('github-protocols'); | |
if (!is_array($protocols)) { | |
throw new \RuntimeException('Config value "github-protocols" must be an array, got '.gettype($protocols)); | |
@@ -317,7 +317,7 @@ class GitDownloader extends VcsDownloader | |
$command = call_user_func($commandCallable, $url); | |
if (0 !== $this->process->execute($command, $ignoredOutput, $cwd)) { | |
// private github repository without git access, try https with auth | |
- if (preg_match('{^git@(github.com):(.+?)\.git$}i', $url, $match)) { | |
+ if (preg_match('{^git@'.$this->getGitHubDomainsRegex().':(.+?)\.git$}i', $url, $match)) { | |
if (!$this->io->hasAuthentication($match[1])) { | |
$gitHubUtil = new GitHub($this->io, $this->config, $this->process); | |
$message = 'Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos'; | |
@@ -368,6 +368,11 @@ class GitDownloader extends VcsDownloader | |
} | |
} | |
+ protected function getGitHubDomainsRegex() | |
+ { | |
+ return '('.implode('|', array_map('preg_quote', $this->config->get('github-domains'))).')'; | |
+ } | |
+ | |
protected function throwException($message, $url) | |
{ | |
if (0 !== $this->process->execute('git --version', $ignoredOutput)) { | |
@@ -385,9 +390,9 @@ class GitDownloader extends VcsDownloader | |
protected function setPushUrl(PackageInterface $package, $path) | |
{ | |
// set push url for github projects | |
- if (preg_match('{^(?:https?|git)://github.com/([^/]+)/([^/]+?)(?:\.git)?$}', $package->getSourceUrl(), $match)) { | |
+ if (preg_match('{^(?:https?|git)://'.$this->getGitHubDomainsRegex().'/([^/]+)/([^/]+?)(?:\.git)?$}', $package->getSourceUrl(), $match)) { | |
$protocols = $this->config->get('github-protocols'); | |
- $pushUrl = '[email protected]:'.$match[1].'/'.$match[2].'.git'; | |
+ $pushUrl = 'git@'.$match[1].':'.$match[2].'/'.$match[3].'.git'; | |
if ($protocols[0] !== 'git') { | |
$pushUrl = 'https://github.com/'.$match[1].'/'.$match[2].'.git'; | |
} | |
diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php | |
index 1d09357..7a0816e 100644 | |
--- a/tests/Composer/Test/Downloader/GitDownloaderTest.php | |
+++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php | |
@@ -24,10 +24,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase | |
$executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor'); | |
$filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem'); | |
if (!$config) { | |
- $config = $this->getMock('Composer\Config'); | |
- $config->expects($this->any()) | |
- ->method('has') | |
- ->will($this->returnValue(false)); | |
+ $config = new Config(); | |
} | |
return new GitDownloader($io, $config, $executor, $filesystem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment