From c8ace5284394746489357ecbd118db5c62056ac0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 26 Jul 2022 18:51:58 +0200 Subject: [PATCH] Make sure git `safe.directory` is disabled before removing `origin` remote --- .../FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php b/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php index cde1f5ba..4d71cbf0 100644 --- a/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php +++ b/src/Git/FetchAndSetCurrentUserByReplacingCurrentOriginRemote.php @@ -24,6 +24,8 @@ 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) { @@ -31,7 +33,6 @@ 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);