diff --git a/src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php b/src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php --- a/src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php +++ b/src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php @@ -76,6 +76,20 @@ PhabricatorRepository $repository, PhabricatorRepositoryURI $mirror_uri) { + // See T5965. Test if we have any refs to mirror. If we have nothing, git + // will exit with an error ("No refs in common and none specified; ...") + // when we run "git push --mirror". + + // If we don't have any refs, we just bail out. (This is arguably sort of + // the wrong behavior: to mirror an empty repository faithfully we should + // delete everything in the remote.) + + list($stdout) = $repository->execxLocalCommand( + 'for-each-ref --count 1 --'); + if (!strlen($stdout)) { + return; + } + $argv = array( 'push --verbose --mirror -- %P', $mirror_uri->getURIEnvelope(), diff --git a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php --- a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php +++ b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php @@ -399,6 +399,11 @@ 'ls-remote %P', $remote_envelope); + // Empty repositories don't have any refs. + if (!strlen(rtrim($stdout))) { + return array(); + } + $map = array(); $lines = phutil_split_lines($stdout, false); foreach ($lines as $line) {