Skip to content

Commit

Permalink
Merge pull request #202 from laminas/fix/prevent-crash-on-duplicate-o…
Browse files Browse the repository at this point in the history
…rigin

Make sure git `safe.directory` is disabled before removing `origin` remote
  • Loading branch information
Ocramius authored Jul 26, 2022
2 parents 6707e44 + c8ace52 commit a11281d
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public function __invoke(
UriInterface $uriWithCredentials,
string $repositoryRootDirectory
): void {
Shell\execute('git', ['config', '--global', '--add', 'safe.directory', '*'], $repositoryRootDirectory);

try {
Shell\execute('git', ['remote', 'rm', 'origin'], $repositoryRootDirectory);
} catch (Shell\Exception\FailedExecutionException) {
}

$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);
Expand Down

0 comments on commit a11281d

Please sign in to comment.