Skip to content

Commit d28ddc2

Browse files
author
epriestley
committed
Don't error when trying to mirror or observe an empty repository
Summary: Fixes T5965. Fixes two issues: - Observing an empty repository could write a warning to the log. - Mirroring an empty repository to a remote could fail. For observing: If newly-created with `git init --bare`, `git ls-remote` will return the empty string. Properly return an empty set of refs, rather than attempting to parse the single "line" that is produced by splitting that on newlines: ``` [2018-01-23 18:47:00] ERROR 8: Undefined offset: 1 at [/phab_path/phabricator/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php:405] arcanist(head=master, ref.master=5634f8410176), phabricator(head=master, ref.master=12551a1055ce), phutil(head=master, ref.master=4755785517cf) #0 PhabricatorRepositoryPullEngine::loadGitRemoteRefs(PhabricatorRepository) called at [<phabricator>/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php:343] #1 PhabricatorRepositoryPullEngine::executeGitUpdate() called at [<phabricator>/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php:126] #2 PhabricatorRepositoryPullEngine::pullRepositoryWithLock() called at [<phabricator>/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php:40] #3 PhabricatorRepositoryPullEngine::pullRepository() called at [<phabricator>/src/applications/repository/management/PhabricatorRepositoryManagementUpdateWorkflow.php:59] ... ``` For mirroring: `git` treats `git push --mirror` specially when a repository is empty. Detect this case by seeing if `git for-each-ref --count 1` does anything. If the repository is empty, just bail. Test Plan: - Observed an empty and non-empty repository. - Mirrored an empty and non-empty repository. Reviewers: alexmv, amckinley Reviewed By: alexmv Subscribers: Korvin, epriestley Maniphest Tasks: T5965 Differential Revision: https://secure.phabricator.com/D18920
1 parent c68a783 commit d28ddc2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/applications/repository/engine/PhabricatorRepositoryMirrorEngine.php

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ private function pushToGitRepository(
7676
PhabricatorRepository $repository,
7777
PhabricatorRepositoryURI $mirror_uri) {
7878

79+
// See T5965. Test if we have any refs to mirror. If we have nothing, git
80+
// will exit with an error ("No refs in common and none specified; ...")
81+
// when we run "git push --mirror".
82+
83+
// If we don't have any refs, we just bail out. (This is arguably sort of
84+
// the wrong behavior: to mirror an empty repository faithfully we should
85+
// delete everything in the remote.)
86+
87+
list($stdout) = $repository->execxLocalCommand(
88+
'for-each-ref --count 1 --');
89+
if (!strlen($stdout)) {
90+
return;
91+
}
92+
7993
$argv = array(
8094
'push --verbose --mirror -- %P',
8195
$mirror_uri->getURIEnvelope(),

src/applications/repository/engine/PhabricatorRepositoryPullEngine.php

+5
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ private function loadGitRemoteRefs(PhabricatorRepository $repository) {
399399
'ls-remote %P',
400400
$remote_envelope);
401401

402+
// Empty repositories don't have any refs.
403+
if (!strlen(rtrim($stdout))) {
404+
return array();
405+
}
406+
402407
$map = array();
403408
$lines = phutil_split_lines($stdout, false);
404409
foreach ($lines as $line) {

0 commit comments

Comments
 (0)