]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix "arc diff" under Mercurial with a dirty working copy
authorepriestley <git@epriestley.com>
Tue, 1 Nov 2011 22:07:39 +0000 (15:07 -0700)
committerepriestley <git@epriestley.com>
Tue, 1 Nov 2011 22:11:48 +0000 (15:11 -0700)
Summary:
In D962, I switched us from using "hg summary" to "hg id" to find the working
copy revision. However, "hg id" reports the revision with a trailing "+" if the
working copy is dirty, so we fail before hitting the explicit check for this
later.

Trim off the trailing '+' if it is present.

Test Plan:
Ran "arc diff" in a dirty Mercurial working copy and got a good error message
about uncommitted changes.

  ~/repos/hg-working-copy $ arc diff
  WARNING: Mercurial support is largely imaginary right now.
  Usage Exception: You have uncommitted changes in this branch. Commit (or
revert) them before proceeding.

    Working copy: /INSECURE/repos/hg-working-copy/

    Uncommitted changes in working copy
      hello.c

Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran

Reviewed By: Makinde

CC: aran, Makinde
Differential Revision: 1070

src/repository/api/mercurial/ArcanistMercurialAPI.php

index 79d80c66de6c4b61c13d7078bf29094ca60c863a..f63b9432311a0d9bf08e569c60c9a4c9abe36894 100644 (file)
@@ -283,7 +283,12 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     list($stdout) = execx(
       '(cd %s && hg --debug id --id)',
       $this->getPath());
-    return trim($stdout);
+
+    // Even with "--id", "hg id" will print a trailing "+" after the hash
+    // if the working copy is dirty (has uncommitted changes). We'll explicitly
+    // detect this later by calling getWorkingCopyStatus(); ignore it for now.
+    $stdout = trim($stdout);
+    return rtrim($stdout, '+');
   }
 
   public function supportsRelativeLocalCommits() {