Differential D20894 Diff 49804 src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
Show First 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | /* -( Pulling Git Working Copies )----------------------------------------- */ | ||||
/** | /** | ||||
* @task git | * @task git | ||||
*/ | */ | ||||
private function executeGitCreate() { | private function executeGitCreate() { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
$path = rtrim($repository->getLocalPath(), '/'); | $path = rtrim($repository->getLocalPath(), '/'); | ||||
if ($repository->isHosted()) { | // See T13448. In all cases, we create repositories by using "git init" | ||||
// to build a bare, empty working copy. If we try to use "git clone" | |||||
// instead, we'll pull in too many refs if "Fetch Refs" is also | |||||
// configured. There's no apparent way to make "git clone" behave narrowly | |||||
// and no apparent reason to bother. | |||||
$repository->execxRemoteCommand( | $repository->execxRemoteCommand( | ||||
'init --bare -- %s', | 'init --bare -- %s', | ||||
$path); | $path); | ||||
} else { | |||||
$repository->execxRemoteCommand( | |||||
'clone --bare -- %P %s', | |||||
$repository->getRemoteURIEnvelope(), | |||||
$path); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* @task git | * @task git | ||||
*/ | */ | ||||
private function executeGitUpdate() { | private function executeGitUpdate() { | ||||
$repository = $this->getRepository(); | $repository = $this->getRepository(); | ||||
list($err, $stdout) = $repository->execLocalCommand( | list($err, $stdout) = $repository->execLocalCommand( | ||||
'rev-parse --show-toplevel'); | 'rev-parse --show-toplevel'); | ||||
$message = null; | $message = null; | ||||
$path = $repository->getLocalPath(); | $path = $repository->getLocalPath(); | ||||
if ($err) { | if ($err) { | ||||
// Try to raise a more tailored error message in the more common case | // Try to raise a more tailored error message in the more common case | ||||
// of the user creating an empty directory. (We could try to remove it, | // of the user creating an empty directory. (We could try to remove it, | ||||
// but might not be able to, and it's much simpler to raise a good | // but might not be able to, and it's much simpler to raise a good | ||||
// message than try to navigate those waters.) | // message than try to navigate those waters.) | ||||
if (is_dir($path)) { | if (is_dir($path)) { | ||||
$files = Filesystem::listDirectory($path, $include_hidden = true); | $files = Filesystem::listDirectory($path, $include_hidden = true); | ||||
if (!$files) { | if (!$files) { | ||||
$message = pht( | $message = pht( | ||||
"Expected to find a git repository at '%s', but there ". | 'Expected to find a Git repository at "%s", but there is an '. | ||||
"is an empty directory there. Remove the directory: the daemon ". | 'empty directory there. Remove the directory. A daemon will '. | ||||
"will run '%s' for you.", | 'construct the working copy for you.', | ||||
$path, | $path); | ||||
'git clone'); | |||||
} else { | } else { | ||||
$message = pht( | $message = pht( | ||||
"Expected to find a git repository at '%s', but there is ". | 'Expected to find a Git repository at "%s", but there is '. | ||||
"a non-repository directory (with other stuff in it) there. Move ". | 'a non-repository directory (with other stuff in it) there. '. | ||||
"or remove this directory (or reconfigure the repository to use a ". | 'Move or remove this directory. A daemon will construct '. | ||||
"different directory), and then either clone a repository ". | 'the working copy for you.', | ||||
"yourself or let the daemon do it.", | |||||
$path); | $path); | ||||
} | } | ||||
} else if (is_file($path)) { | } else if (is_file($path)) { | ||||
$message = pht( | $message = pht( | ||||
"Expected to find a git repository at '%s', but there is a ". | 'Expected to find a Git repository at "%s", but there is a '. | ||||
"file there instead. Remove it and let the daemon clone a ". | 'file there instead. Move or remove this file. A daemon will '. | ||||
"repository for you.", | 'construct the working copy for you.', | ||||
$path); | $path); | ||||
} else { | } else { | ||||
$message = pht( | $message = pht( | ||||
"Expected to find a git repository at '%s', but did not.", | 'Expected to find a git repository at "%s", but did not.', | ||||
$path); | $path); | ||||
} | } | ||||
} else { | } else { | ||||
$repo_path = rtrim($stdout, "\n"); | $repo_path = rtrim($stdout, "\n"); | ||||
if (empty($repo_path)) { | if (empty($repo_path)) { | ||||
// This can mean one of two things: we're in a bare repository, or | // This can mean one of two things: we're in a bare repository, or | ||||
// we're inside a git repository inside another git repository. Since | // we're inside a git repository inside another git repository. Since | ||||
// the first is dramatically more likely now that we perform bare | // the first is dramatically more likely now that we perform bare | ||||
// clones and I don't have a great way to test for the latter, assume | // clones and I don't have a great way to test for the latter, assume | ||||
// we're OK. | // we're OK. | ||||
} else if (!Filesystem::pathsAreEquivalent($repo_path, $path)) { | } else if (!Filesystem::pathsAreEquivalent($repo_path, $path)) { | ||||
$err = true; | $err = true; | ||||
$message = pht( | $message = pht( | ||||
"Expected to find repo at '%s', but the actual git repository root ". | 'Expected to find a Git repository at "%s", but the actual Git '. | ||||
"for this directory is '%s'. Something is misconfigured. ". | 'repository root for this directory is "%s". Something is '. | ||||
"The repository's 'Local Path' should be set to some place where ". | 'misconfigured. This directory should be writable by the daemons '. | ||||
"the daemon can check out a working copy, ". | 'and not inside another Git repository.', | ||||
"and should not be inside another git repository.", | |||||
$path, | $path, | ||||
$repo_path); | $repo_path); | ||||
} | } | ||||
} | } | ||||
if ($err && $repository->canDestroyWorkingCopy()) { | if ($err && $repository->canDestroyWorkingCopy()) { | ||||
phlog( | phlog( | ||||
pht( | pht( | ||||
▲ Show 20 Lines • Show All 480 Lines • Show Last 20 Lines |