]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix "arc diff --raw-command --create"
authorepriestley <git@epriestley.com>
Sat, 17 May 2014 20:40:05 +0000 (13:40 -0700)
committerepriestley <git@epriestley.com>
Sat, 17 May 2014 20:40:05 +0000 (13:40 -0700)
Summary: Fixes T5082. We try to access the repository API in some cases when we don't have one.

Test Plan:
  - Made revisions with "arc diff --raw-command --create".
  - Made this revision, without "--raw-command".

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5082

Differential Revision: https://secure.phabricator.com/D9165

src/workflow/ArcanistBaseWorkflow.php
src/workflow/ArcanistDiffWorkflow.php

index 9ebe9d2049828d33ee52b9fd9d887ac6a9dc33d8..1353200836bcbfb2bbfd5587f3b9b1f638f6c335 100644 (file)
@@ -760,6 +760,14 @@ abstract class ArcanistBaseWorkflow extends Phobject {
     return $this;
   }
 
+  public function hasRepositoryAPI() {
+    try {
+      return (bool)$this->getRepositoryAPI();
+    } catch (Exception $ex) {
+      return false;
+    }
+  }
+
   public function getRepositoryAPI() {
     if (!$this->repositoryAPI) {
       $workflow = get_class($this);
index 19ebe662df4cb1d0fd182b7bc57e819289014db9..393bf3de06bf5487117e5432651db994262279a6 100644 (file)
@@ -1169,11 +1169,11 @@ EOTEXT
   }
 
   private function shouldAmend() {
-    if ($this->haveUncommittedChanges) {
+    if ($this->isRawDiffSource()) {
       return false;
     }
 
-    if ($this->isHistoryImmutable()) {
+    if ($this->haveUncommittedChanges) {
       return false;
     }
 
@@ -1181,7 +1181,9 @@ EOTEXT
       return false;
     }
 
-    if ($this->isRawDiffSource()) {
+    // Run this last: with --raw or --raw-command, we won't have a repository
+    // API.
+    if ($this->isHistoryImmutable()) {
       return false;
     }
 
@@ -1638,13 +1640,19 @@ EOTEXT
 
       $template = ArcanistCommentRemover::removeComments($new_template);
 
-      $repository_api = $this->getRepositoryAPI();
-      // special check for whether to amend here. optimizes a common git
-      // workflow. we can't do this for mercurial because the mq extension
-      // is popular and incompatible with hg commit --amend ; see T2011.
-      $should_amend = (count($included_commits) == 1 &&
-                       $repository_api instanceof ArcanistGitAPI &&
-                       $this->shouldAmend());
+      // With --raw-command, we may not have a repository API.
+      if ($this->hasRepositoryAPI()) {
+        $repository_api = $this->getRepositoryAPI();
+        // special check for whether to amend here. optimizes a common git
+        // workflow. we can't do this for mercurial because the mq extension
+        // is popular and incompatible with hg commit --amend ; see T2011.
+        $should_amend = (count($included_commits) == 1 &&
+                         $repository_api instanceof ArcanistGitAPI &&
+                         $this->shouldAmend());
+      } else {
+        $should_amend = false;
+      }
+
       if ($should_amend) {
         $wrote = (rtrim($old_message) != rtrim($template));
         if ($wrote) {