Path: blob/master/src/applications/differential/DifferentialGetWorkingCopy.php
12249 views
<?php12/**3* Can't find a good place for this, so I'm putting it in the most notably4* wrong place.5*/6final class DifferentialGetWorkingCopy extends Phobject {78/**9* Creates and/or cleans a workspace for the requested repo.10*11* return ArcanistGitAPI12*/13public static function getCleanGitWorkspace(14PhabricatorRepository $repo) {1516$origin_path = $repo->getLocalPath();1718$path = rtrim($origin_path, '/');19$path = $path.'__workspace';2021if (!Filesystem::pathExists($path)) {22$repo->execxLocalCommand(23'clone -- file://%s %s',24$origin_path,25$path);2627if (!$repo->isHosted()) {28id(new ArcanistGitAPI($path))->execxLocal(29'remote set-url origin %s',30$repo->getRemoteURI());31}32}3334$workspace = new ArcanistGitAPI($path);35$workspace->execxLocal('clean -f -d');36$workspace->execxLocal('checkout master');37$workspace->execxLocal('fetch');38$workspace->execxLocal('reset --hard origin/master');39$workspace->reloadWorkingCopy();4041return $workspace;42}4344/**45* Creates and/or cleans a workspace for the requested repo.46*47* return ArcanistMercurialAPI48*/49public static function getCleanMercurialWorkspace(50PhabricatorRepository $repo) {5152$origin_path = $repo->getLocalPath();5354$path = rtrim($origin_path, '/');55$path = $path.'__workspace';5657if (!Filesystem::pathExists($path)) {58$repo->execxLocalCommand(59'clone -- file://%s %s',60$origin_path,61$path);62}6364$workspace = new ArcanistMercurialAPI($path);65$workspace->execxLocal('pull');66$workspace->execxLocal('update --clean default');67$workspace->reloadWorkingCopy();6869return $workspace;70}7172}737475