diff --git a/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php b/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php index 4e9390a2..cde1f5ba 100644 --- a/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php +++ b/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php @@ -31,6 +31,7 @@ public function __invoke( $credentialStore = Filesystem\create_temporary_file(); + Shell\execute('git', ['config', '--global', '--add', 'safe.directory', '*'], $repositoryRootDirectory); Shell\execute('git', ['config', 'credential.helper', 'store --file=' . $credentialStore], $repositoryRootDirectory); File\write($credentialStore, $uriWithCredentials->__toString()); Shell\execute('git', ['remote', 'add', 'origin', $repositoryUri->__toString()], $repositoryRootDirectory); diff --git a/test/unit/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemoteTest.php b/test/unit/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemoteTest.php index e0bdb193..a4547a11 100644 --- a/test/unit/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemoteTest.php +++ b/test/unit/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemoteTest.php @@ -129,4 +129,20 @@ public function testFailingToSetARemoteWillNotLeadToSecretExfiltration(): void self::assertDoesNotMatchRegularExpression('/SUPERSECRET/m', $failure->getMessage()); } } + + public function testGlobalGitConfigurationIsAdaptedToAllowCheckedOutRepositoryUsage(): void + { + $sourceUri = $this->createMock(UriInterface::class); + + $sourceUri->method('__toString') + ->willReturn($this->source); + + (new FetchAndSetCurrentUserByReplacingCurrentOriginRemote($this->variables)) + ->__invoke($sourceUri, $sourceUri, $this->destination); + + self::assertSame( + '*', + Str\trim(Shell\execute('git', ['config', '--get', 'safe.directory'], $this->destination)) + ); + } }