1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

GitDriver: try to fetch default branch form remote using auth (#10701)

This commit is contained in:
Stephan 2022-04-13 11:11:25 +01:00 committed by GitHub
parent 54063964a7
commit 866d2a49b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 18 deletions

View file

@ -42,12 +42,43 @@ class GitDriverTest extends TestCase
}
}
public function testGetRootIdentifierFromRemoteLocalRepository(): void
{
$process = $this->getProcessExecutorMock();
$io = $this->getMockBuilder(IOInterface::class)->getMock();
$driver = new GitDriver(['url' => $this->home], $io, $this->config, $this->getHttpDownloaderMock(), $process);
$this->setRepoDir($driver, $this->home);
$stdoutFailure = <<<GITFAILURE
fatal: could not read Username for 'https://example.org/acme.git': terminal prompts disabled
GITFAILURE;
$stdout = <<<GIT
* main
2.2
1.10
GIT;
$process
->expects([[
'cmd' => 'git remote show origin',
'stdout' => $stdoutFailure,
], [
'cmd' => 'git branch --no-color',
'stdout' => $stdout,
]]);
$this->assertSame('main', $driver->getRootIdentifier());
}
public function testGetRootIdentifierFromRemote(): void
{
$process = $this->getProcessExecutorMock();
$io = $this->getMockBuilder(IOInterface::class)->getMock();
$driver = new GitDriver(['url' => 'https://example.org/acme.git'], $io, $this->config, $this->getHttpDownloaderMock(), $process);
$this->setRepoDir($driver, $this->home);
$stdout = <<<GIT
* remote origin
@ -62,7 +93,10 @@ GIT;
$process
->expects([[
'cmd' => 'git remote show origin',
'cmd' => 'git remote -v',
'stdout' => '',
],[
'cmd' => "git remote set-url origin -- 'https://example.org/acme.git' && git remote show origin && git remote set-url origin -- 'https://example.org/acme.git'",
'stdout' => $stdout,
]]);
@ -77,6 +111,7 @@ GIT;
$io = $this->getMockBuilder(IOInterface::class)->getMock();
$driver = new GitDriver(['url' => 'https://example.org/acme.git'], $io, $this->config, $this->getHttpDownloaderMock(), $process);
$this->setRepoDir($driver, $this->home);
$stdout = <<<GIT
* main
@ -92,4 +127,12 @@ GIT;
$this->assertSame('main', $driver->getRootIdentifier());
}
private function setRepoDir(GitDriver $driver, string $path): void
{
$reflectionClass = new \ReflectionClass($driver);
$reflectionProperty = $reflectionClass->getProperty('repoDir');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($driver, $path);
}
}