From c84d6255b4a8a6be539b615e36977458de49e02c Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 25 Aug 2011 17:53:59 -0700 Subject: [PATCH] Support "immutable_history" doctrine in arc Summary: When a project uses a conservative history mutability doctrine, never try to amend history. Test Plan: Ran "arc amend" in an "immutable_history" working copy. Reviewers: fratrik, Makinde, aran, jungejason, tuomaspelkonen Reviewed By: Makinde CC: aran, Makinde, epriestley Differential Revision: 862 --- src/workflow/amend/ArcanistAmendWorkflow.php | 8 ++++++++ src/workflow/base/ArcanistBaseWorkflow.php | 5 +++++ src/workflow/diff/ArcanistDiffWorkflow.php | 11 ++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/workflow/amend/ArcanistAmendWorkflow.php b/src/workflow/amend/ArcanistAmendWorkflow.php index e722e137..de5a33db 100644 --- a/src/workflow/amend/ArcanistAmendWorkflow.php +++ b/src/workflow/amend/ArcanistAmendWorkflow.php @@ -65,6 +65,14 @@ EOTEXT } public function run() { + if ($this->isHistoryImmutable()) { + throw new ArcanistUsageException( + "This project is marked as adhering to a conservative history ". + "mutability doctrine (having an immutable local history), which ". + "precludes amending commit messages. You can use 'arc merge' to ". + "merge feature branches instead."); + } + $repository_api = $this->getRepositoryAPI(); if (!($repository_api instanceof ArcanistGitAPI)) { throw new ArcanistUsageException( diff --git a/src/workflow/base/ArcanistBaseWorkflow.php b/src/workflow/base/ArcanistBaseWorkflow.php index 6a5a242b..9bf75f58 100644 --- a/src/workflow/base/ArcanistBaseWorkflow.php +++ b/src/workflow/base/ArcanistBaseWorkflow.php @@ -913,4 +913,9 @@ class ArcanistBaseWorkflow { file_put_contents('php://stderr', $msg); } + protected function isHistoryImmutable() { + $working_copy = $this->getWorkingCopy(); + return ($working_copy->getConfig('immutable_history') === true); + } + } diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index 2a25f73a..b10e0ade 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -549,8 +549,10 @@ EOTEXT } if ($repository_api instanceof ArcanistMercurialAPI) { - // TODO: This is unlikely to be correct since it excludes using local - // branching in Mercurial. + return true; + } + + if ($this->isHistoryImmutable()) { return true; } @@ -1110,7 +1112,10 @@ EOTEXT } $lint_workflow = $this->buildChildWorkflow('lint', $argv); - $lint_workflow->setShouldAmendChanges(true); + if (!$this->isHistoryImmutable()) { + // TODO: We should offer to create a checkpoint commit. + $lint_workflow->setShouldAmendChanges(true); + } $lint_result = $lint_workflow->run();