function Git::syncMirror
1 call to Git::syncMirror()
- Git::fetchRefOrSyncMirror in vendor/
composer/ composer/ src/ Composer/ Util/ Git.php
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Git.php, line 366
Class
- Git
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\UtilCode
public function syncMirror(string $url, string $dir) : bool {
if ((bool) Platform::getEnv('COMPOSER_DISABLE_NETWORK') && Platform::getEnv('COMPOSER_DISABLE_NETWORK') !== 'prime') {
$this->io
->writeError('<warning>Aborting git mirror sync of ' . $url . ' as network is disabled</warning>');
return false;
}
// update the repo if it is a valid git repository
if (is_dir($dir) && 0 === $this->process
->execute([
'git',
'rev-parse',
'--git-dir',
], $output, $dir) && trim($output) === '.') {
try {
$commands = [
[
'git',
'remote',
'set-url',
'origin',
'--',
'%url%',
],
[
'git',
'remote',
'update',
'--prune',
'origin',
],
[
'git',
'remote',
'set-url',
'origin',
'--',
'%sanitizedUrl%',
],
[
'git',
'gc',
'--auto',
],
];
$this->runCommands($commands, $url, $dir);
} catch (\Exception $e) {
$this->io
->writeError('<error>Sync mirror failed: ' . $e->getMessage() . '</error>', true, IOInterface::DEBUG);
return false;
}
return true;
}
self::checkForRepoOwnershipError($this->process
->getErrorOutput(), $dir);
// clean up directory and do a fresh clone into it
$this->filesystem
->removeDirectory($dir);
$this->runCommands([
[
'git',
'clone',
'--mirror',
'--',
'%url%',
$dir,
],
], $url, $dir, true);
return true;
}