]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow anyone to run `arc commit` on an accepted revision
authorMarek Sapota <mareksapota@fb.com>
Wed, 26 Oct 2011 03:03:41 +0000 (20:03 -0700)
committerMarek Sapota <mareksapota@fb.com>
Fri, 28 Oct 2011 16:18:32 +0000 (09:18 -0700)
Test Plan:
Using SVN make some changes to the repo, run `arc diff`.  As other user accept
the revision, add the changes to your repo using `arc patch` and then run `arc
commit --revision revisionID` to commit them.  Arcanist should ask if you are
sure that you want to commit this revision and if you answer `Y` it should
commit to SNV repo.

Reviewers: epriestley, jungejason

Reviewed By: epriestley

CC: aran, mareksapota, epriestley
Differential Revision: 1055

src/workflow/commit/ArcanistCommitWorkflow.php
src/workflow/mark-committed/ArcanistMarkCommittedWorkflow.php

index 27b29aa59b345d983a995eab7c1f3daa29186563..d40a837d39375897d9471fb86c60329d81954585 100644 (file)
@@ -68,33 +68,63 @@ EOTEXT
     $repository_api = $this->getRepositoryAPI();
     $conduit = $this->getConduit();
 
-    $revision_data = $conduit->callMethodSynchronous(
-      'differential.find',
-      array(
-        'query' => 'committable',
-        'guids' => array(
-          $this->getUserPHID(),
-        ),
-      ));
+    $revision_id = $this->getArgument('revision');
+
+    if (!$revision_id) {
+      $revision_data = $conduit->callMethodSynchronous(
+        'differential.find',
+        array(
+          'query' => 'committable',
+          'guids' => array(
+            $this->getUserPHID(),
+          ),
+        )
+      );
+
+      try {
+        $revision = $this->chooseRevision(
+          $revision_data,
+          null,
+          'Which revision do you want to commit?'
+        );
+        $revision_id = $revision->getID();
+      } catch (ArcanistChooseNoRevisionsException $ex) {
+        throw new ArcanistUsageException(
+          "You have no committable Differential revisions. You can only ".
+          "commit revisions which have been 'accepted'.");
+      }
+    }
 
+    $revision = null;
     try {
-      $revision_id = $this->getArgument('revision');
-      $revision = $this->chooseRevision(
-        $revision_data,
-        $revision_id,
-        'Which revision do you want to commit?');
-    } catch (ArcanistChooseInvalidRevisionException $ex) {
+      $revision = $conduit->callMethodSynchronous(
+        'differential.getrevision',
+        array(
+          'revision_id' => $revision_id,
+        )
+      );
+    } catch (Exception $ex) {
       throw new ArcanistUsageException(
-        "Revision D{$revision_id} is not committable. You can only commit ".
-        "revisions you own which have been 'accepted'.");
-    } catch (ArcanistChooseNoRevisionsException $ex) {
+        "Revision D{$revision_id} does not exist."
+      );
+    }
+
+    if ($revision['statusName'] != 'Accepted') {
       throw new ArcanistUsageException(
-        "You have no committable Differential revisions. You can only commit ".
-        "revisions you own which have been 'accepted'.");
+        "Revision D{$revision_id} is not committable. You can only commit ".
+        "revisions which have been 'accepted'."
+      );
+    }
+
+    if ($revision['authorPHID'] != $this->getUserPHID()) {
+      $prompt = "You are not the author of revision D{$revision_id}, ".
+        'are you sure you want to commit it?';
+      if (!phutil_console_confirm($prompt)) {
+        throw new ArcanistUserAbortException();
+      }
     }
 
-    $revision_id    = $revision->getID();
-    $revision_name  = $revision->getName();
+    $revision_name  = $revision['title'];
 
     $message = $conduit->callMethodSynchronous(
       'differential.getcommitmessage',
@@ -140,8 +170,7 @@ EOTEXT
     return $err;
   }
 
-  protected function getCommitFileList(
-    ArcanistDifferentialRevisionRef $revision) {
+  protected function getCommitFileList(array $revision) {
     $repository_api = $this->getRepositoryAPI();
 
     if (!($repository_api instanceof ArcanistSubversionAPI)) {
@@ -151,9 +180,22 @@ EOTEXT
 
     $conduit = $this->getConduit();
 
-    $revision_id = $revision->getID();
+    $revision_id = $revision['id'];
+
+    $revision = reset($conduit->callMethodSynchronous(
+      'differential.find',
+      array(
+        'query' => 'revision-ids',
+        'guids' => array($revision_id,)
+      )
+    ));
+    if (!$revision) {
+      throw new ArcanistUsageException(
+        "Revision D{$revision_id} does not exist."
+      );
+    }
+    $revision_source = $revision['sourcePath'];
 
-    $revision_source = $revision->getSourcePath();
     $working_copy = $repository_api->getPath();
     if ($revision_source != $working_copy) {
       $prompt =
index bcfaa9b74abaf01e1adab0d9b028450e156db6cd..654b9718a9285bdafa79ec666fbe3d8b8ca7535d 100644 (file)
@@ -106,7 +106,7 @@ EOTEXT
     }
 
     if ($revision) {
-      if ($revision['authorPHID'] != $this->getUserPHID()) {
+      if (!$is_finalize && $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)) {