From 6db055222a5e927de63a072088cfdc633f398b96 Mon Sep 17 00:00:00 2001 From: Marek Sapota Date: Tue, 25 Oct 2011 16:34:15 -0700 Subject: [PATCH] Allow anyone to mark Differential revisions as commited. Test Plan: Run `arc mark-committed` on a revision that you don't own, you should see a prompt asking you if you really want to do that and if you answer `Y` it should mark the revision as committed. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley, mareksapota Differential Revision: 1052 --- .../ArcanistMarkCommittedWorkflow.php | 55 ++++++++++--------- src/workflow/mark-committed/__init__.php | 1 + 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/workflow/mark-committed/ArcanistMarkCommittedWorkflow.php b/src/workflow/mark-committed/ArcanistMarkCommittedWorkflow.php index 74c0eee4..bcfaa9b7 100644 --- a/src/workflow/mark-committed/ArcanistMarkCommittedWorkflow.php +++ b/src/workflow/mark-committed/ArcanistMarkCommittedWorkflow.php @@ -79,32 +79,41 @@ EOTEXT throw new ArcanistUsageException( "mark-committed requires exactly one revision."); } - - $revision_data = $conduit->callMethodSynchronous( - 'differential.find', - array( - 'query' => 'committable', - 'guids' => array( - $this->getUserPHID(), - ), - )); + $revision_id = reset($revision_list); + $revision_id = $this->normalizeRevisionID($revision_id); $revision = null; try { - $revision_id = reset($revision_list); - $revision_id = $this->normalizeRevisionID($revision_id); - $revision = $this->chooseRevision( - $revision_data, - $revision_id); - } catch (ArcanistChooseInvalidRevisionException $ex) { + $revision = $conduit->callMethodSynchronous( + 'differential.getrevision', + array( + 'revision_id' => $revision_id, + ) + ); + } catch (Exception $ex) { if (!$is_finalize) { throw new ArcanistUsageException( - "Revision D{$revision_id} is not committable. You can only mark ". - "revisions which have been 'accepted' as committed."); + "Revision D{$revision_id} does not exist." + ); } } + if (!$is_finalize && $revision['statusName'] != 'Accepted') { + throw new ArcanistUsageException( + "Revision D{$revision_id} is not committable. You can only mark ". + "revisions which have been 'accepted' as committed." + ); + } + if ($revision) { + if ($revision['authorPHID'] != $this->getUserPHID()) { + $prompt = "You are not the author of revision D{$revision_id}, ". + 'are you sure you want to mark it committed?'; + if (!phutil_console_confirm($prompt)) { + throw new ArcanistUserAbortException(); + } + } + $actually_mark = true; if ($is_finalize) { $project_info = $conduit->callMethodSynchronous( @@ -117,8 +126,7 @@ EOTEXT } } if ($actually_mark) { - $revision_id = $revision->getID(); - $revision_name = $revision->getName(); + $revision_name = $revision['title']; echo "Marking revision D{$revision_id} '{$revision_name}' ". "committed...\n"; @@ -131,17 +139,12 @@ EOTEXT } } - $revision_info = $conduit->callMethodSynchronous( - 'differential.getrevision', - array( - 'revision_id' => $revision_id, - )); - $status = $revision_info['statusName']; + $status = $revision['statusName']; if ($status == 'Accepted' || $status == 'Committed') { // If this has already been attached to commits, don't show the // "you can push this commit" message since we know it's been committed // already. - $is_finalized = empty($revision_info['commits']); + $is_finalized = empty($revision['commits']); } else { $is_finalized = false; } diff --git a/src/workflow/mark-committed/__init__.php b/src/workflow/mark-committed/__init__.php index 83bdcd8d..cfeea091 100644 --- a/src/workflow/mark-committed/__init__.php +++ b/src/workflow/mark-committed/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('arcanist', 'exception/usage'); +phutil_require_module('arcanist', 'exception/usage/userabort'); phutil_require_module('arcanist', 'workflow/base'); phutil_require_module('phutil', 'console');