]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix some arc/mercurial issues
authorepriestley <git@epriestley.com>
Tue, 17 Jul 2012 23:16:11 +0000 (16:16 -0700)
committerepriestley <git@epriestley.com>
Tue, 17 Jul 2012 23:16:11 +0000 (16:16 -0700)
Summary:
  - In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
  - When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
  - If you have uncommitted working copy changes, never try to amend.

Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.

Reviewers: dschleimer, btrahan

Reviewed By: btrahan

CC: aran
Maniphest Tasks: T1507

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

src/repository/api/ArcanistMercurialAPI.php
src/workflow/ArcanistDiffWorkflow.php
src/workflow/ArcanistWhichWorkflow.php

index e0f3aef37c70dc4f46e5c622ec469091cbf795be..cd22344bd5536a6b1449d19b098da78a94502a2e 100644 (file)
@@ -417,9 +417,9 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
   public function supportsAmend() {
     list ($err, $stdout) = $this->execManualLocal('help commit');
     if ($err) {
-        return false;
+      return false;
     } else {
-        return (strstr($stdout, "amend") !== false);
+      return (strstr($stdout, "amend") !== false);
     }
   }
 
@@ -553,19 +553,27 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
       $hashes[] = array('hgcm', $commit['commit']);
     }
 
-    $results = $conduit->callMethodSynchronous(
-      'differential.query',
-      $query + array(
-        'commitHashes' => $hashes,
-      ));
+    if ($hashes) {
+
+      // NOTE: In the case of "arc diff . --uncommitted" in a Mercurial working
+      // copy with dirty changes, there may be no local commits.
 
-    foreach ($results as $key => $hash) {
-      $results[$key]['why'] =
-        "A mercurial commit hash in the commit range is already attached ".
-        "to the Differential revision.";
+      $results = $conduit->callMethodSynchronous(
+        'differential.query',
+        $query + array(
+          'commitHashes' => $hashes,
+        ));
+
+      foreach ($results as $key => $hash) {
+        $results[$key]['why'] =
+          "A mercurial commit hash in the commit range is already attached ".
+          "to the Differential revision.";
+      }
+
+      return $results;
     }
 
-    return $results;
+    return array();
   }
 
   public function updateWorkingCopy() {
index 73c36f2333c4529bf29b40d42efbed652531aba4..f45548f04cecff6cc120c74c5cdae7385e4d1b93 100644 (file)
@@ -38,6 +38,7 @@ final class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
   private $unitWorkflow;
   private $lintWorkflow;
   private $postponedLinters;
+  private $haveUncommittedChanges = false;
 
   public function getCommandSynopses() {
     return phutil_console_format(<<<EOTEXT
@@ -297,7 +298,7 @@ EOTEXT
         'help' => 'Never amend commits in the working copy.',
       ),
       'uncommitted' => array(
-        'help' => 'Include uncommitted changes without prompting.',
+        'help' => 'Suppress warning about uncommitted changes.',
         'supports' => array(
           'hg',
         ),
@@ -486,9 +487,8 @@ EOTEXT
             'revision_id' => $result['revisionid'],
           ));
 
-        if (!$this->isRawDiffSource() && $this->shouldAmend()) {
+        if ($this->shouldAmend()) {
           $repository_api = $this->getRepositoryAPI();
-
           if ($repository_api->supportsAmend()) {
             echo "Updating commit message...\n";
             $repository_api->amendCommit($revised_message);
@@ -577,6 +577,7 @@ EOTEXT
           }
 
           $repository_api->setIncludeDirectoryStateInDiffs(true);
+          $this->haveUncommittedChanges = true;
         }
       }
     }
@@ -1070,7 +1071,23 @@ EOTEXT
   }
 
   private function shouldAmend() {
-    return !$this->isHistoryImmutable() && !$this->getArgument('no-amend');
+    if ($this->haveUncommittedChanges) {
+      return false;
+    }
+
+    if ($this->isHistoryImmutable()) {
+      return false;
+    }
+
+    if ($this->getArgument('no-amend')) {
+      return false;
+    }
+
+    if ($this->isRawDiffSource()) {
+      return false;
+    }
+
+    return true;
   }
 
 
index 7178320e358678f4d7e2fe036558f1856dd004ad..e429fe81594389980755b996b83674aef92d0483 100644 (file)
@@ -127,7 +127,7 @@ EOTEXT
       if ($repository_api instanceof ArcanistGitAPI) {
         $command = "git diff {$relative}..HEAD";
       } else if ($repository_api instanceof ArcanistMercurialAPI) {
-        $command = "hg diff --rev {$relative} --rev .";
+        $command = "hg diff --rev {$relative}";
       } else {
         throw new Exception("Unknown VCS!");
       }