Skip to content

Commit

Permalink
Merge pull request #200 from laminas/fix/#198-allow-git-operations-on…
Browse files Browse the repository at this point in the history
…-any-directory

Fix #198 - make GIT's `safe.directory` `'*'` by default on repository fetch
  • Loading branch information
Ocramius authored Jul 26, 2022
2 parents 72e81b1 + bc11f09 commit 22eed25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}
}

0 comments on commit 22eed25

Please sign in to comment.