From 89753d5d4961e70ee7b7c2e71a60b16ae79a42b0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 16 Mar 2012 13:40:33 -0700 Subject: [PATCH] Don't fatal without Conduit for "--patch" and "--bundle" Summary: In some workflows, we don't have Conduit at all, so we'll fail with a raw exception. Test for conduit presence before trying to make the encoding call. Also move some "instanceof" logic for updates into RepositoryAPI (factoring, windows compat). Test Plan: Ran "arc patch --patch some.patch". Reviewers: 20after4, davidreuss, nh, btrahan Reviewed By: 20after4 CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1935 --- .../api/base/ArcanistRepositoryAPI.php | 1 + src/repository/api/git/ArcanistGitAPI.php | 4 +++ .../api/mercurial/ArcanistMercurialAPI.php | 4 +++ .../api/subversion/ArcanistSubversionAPI.php | 4 +++ src/workflow/patch/ArcanistPatchWorkflow.php | 34 +++++-------------- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/repository/api/base/ArcanistRepositoryAPI.php b/src/repository/api/base/ArcanistRepositoryAPI.php index 534b2408..d97aa882 100644 --- a/src/repository/api/base/ArcanistRepositoryAPI.php +++ b/src/repository/api/base/ArcanistRepositoryAPI.php @@ -160,6 +160,7 @@ abstract class ArcanistRepositoryAPI { abstract public function getCanonicalRevisionName($string); abstract public function supportsRelativeLocalCommits(); abstract public function getWorkingCopyRevision(); + abstract public function updateWorkingCopy(); abstract public function loadWorkingCopyDifferentialRevisions( ConduitClient $conduit, array $query); diff --git a/src/repository/api/git/ArcanistGitAPI.php b/src/repository/api/git/ArcanistGitAPI.php index 0b8fb562..ecbc5b45 100644 --- a/src/repository/api/git/ArcanistGitAPI.php +++ b/src/repository/api/git/ArcanistGitAPI.php @@ -672,4 +672,8 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { return $results; } + public function updateWorkingCopy() { + $this->execxLocal('pull'); + } + } diff --git a/src/repository/api/mercurial/ArcanistMercurialAPI.php b/src/repository/api/mercurial/ArcanistMercurialAPI.php index 9804dde5..c78f38ee 100644 --- a/src/repository/api/mercurial/ArcanistMercurialAPI.php +++ b/src/repository/api/mercurial/ArcanistMercurialAPI.php @@ -430,4 +430,8 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { return $results; } + public function updateWorkingCopy() { + $this->execxLocal('up'); + } + } diff --git a/src/repository/api/subversion/ArcanistSubversionAPI.php b/src/repository/api/subversion/ArcanistSubversionAPI.php index 4498b60a..9c0c3ae6 100644 --- a/src/repository/api/subversion/ArcanistSubversionAPI.php +++ b/src/repository/api/subversion/ArcanistSubversionAPI.php @@ -549,4 +549,8 @@ EODIFF; return $results; } + public function updateWorkingCopy() { + $this->execxLocal('up'); + } + } diff --git a/src/workflow/patch/ArcanistPatchWorkflow.php b/src/workflow/patch/ArcanistPatchWorkflow.php index 2241fe66..536154d6 100644 --- a/src/workflow/patch/ArcanistPatchWorkflow.php +++ b/src/workflow/patch/ArcanistPatchWorkflow.php @@ -298,27 +298,9 @@ EOTEXT } private function updateWorkingCopy() { - $repository_api = $this->getRepositoryAPI(); - if ($repository_api instanceof ArcanistSubversionAPI) { - execx( - '(cd %s; svn up)', - $repository_api->getPath()); - $message = "Updated to HEAD. "; - } else if ($repository_api instanceof ArcanistGitAPI) { - execx( - '(cd %s; git pull)', - $repository_api->getPath()); - $message = "Updated to HEAD. "; - } else if ($repository_api instanceof ArcanistMercurialAPI) { - execx( - '(cd %s; hg up)', - $repository_api->getPath()); - $message = "Updated to tip. "; - } else { - throw new Exception('Unknown version control system.'); - } - - echo phutil_console_format($message."\n"); + echo "Updating working copy...\n"; + $this->getRepositoryAPI()->updateWorkingCopy(); + echo "Done.\n"; } public function run() { @@ -367,10 +349,12 @@ EOTEXT $try_encoding = nonempty($this->getArgument('encoding'), null); if (!$try_encoding) { - try { - $try_encoding = $this->getRepositoryEncoding(); - } catch (ConduitClientException $e) { - $try_encoding = null; + if ($this->requiresConduit()) { + try { + $try_encoding = $this->getRepositoryEncoding(); + } catch (ConduitClientException $e) { + $try_encoding = null; + } } }