1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 11:22:40 +01:00
phorge-phorge/src/applications/differential/DifferentialGetWorkingCopy.php
Asher Baker d700e7f22d Add support for landing to hosted Mercurial repos.
Summary: I've kept this as close as possible to the Git version for ease of review and later refactoring of them both together. At minimum, the functions to get the working dir should probably be cleaned up one day.

Test Plan: Landed a revision.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D7534
2013-11-08 11:39:32 -08:00

67 lines
1.5 KiB
PHP

<?php
/**
* Can't find a good place for this, so I'm putting it in the most notably
* wrong place.
*/
final class DifferentialGetWorkingCopy {
/**
* Creates and/or cleans a workspace for the requested repo.
*
* return ArcanistGitAPI
*/
public static function getCleanGitWorkspace(
PhabricatorRepository $repo) {
$origin_path = $repo->getLocalPath();
$path = rtrim($origin_path, '/');
$path = $path . '__workspace';
if (!Filesystem::pathExists($path)) {
$repo->execxLocalCommand(
'clone -- file://%s %s',
$origin_path,
$path);
}
$workspace = new ArcanistGitAPI($path);
$workspace->execxLocal('clean -f -d');
$workspace->execxLocal('checkout master');
$workspace->execxLocal('fetch');
$workspace->execxLocal('reset --hard origin/master');
$workspace->reloadWorkingCopy();
return $workspace;
}
/**
* Creates and/or cleans a workspace for the requested repo.
*
* return ArcanistMercurialAPI
*/
public static function getCleanMercurialWorkspace(
PhabricatorRepository $repo) {
$origin_path = $repo->getLocalPath();
$path = rtrim($origin_path, '/');
$path = $path . '__workspace';
if (!Filesystem::pathExists($path)) {
$repo->execxLocalCommand(
'clone -- file://%s %s',
$origin_path,
$path);
}
$workspace = new ArcanistMercurialAPI($path);
$workspace->execxLocal('pull');
$workspace->execxLocal('update --clean default');
$workspace->reloadWorkingCopy();
return $workspace;
}
}