]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Enable lint amending commits in mercurial
authordurham <durham@fb.com>
Tue, 16 Apr 2013 20:32:12 +0000 (13:32 -0700)
committerdurham <durham@fb.com>
Tue, 16 Apr 2013 20:32:12 +0000 (13:32 -0700)
Summary:
arc lint was hardcoded for git for amending commits with lint
patches. This enables the same functionality for mercurial.

Test Plan:
Made some changes that would result in a lint patch.
arc diff

Verify that the patches it produces were amended into the commit.

Verified it still works in git as well.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5716

src/repository/api/ArcanistGitAPI.php
src/repository/api/ArcanistMercurialAPI.php
src/repository/api/ArcanistRepositoryAPI.php
src/workflow/ArcanistLintWorkflow.php

index bcf0a87631efbe24d002d03544c5725f2039e916..4367a035c3363722482596f925b30f6b832cff03 100644 (file)
@@ -514,12 +514,17 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     return $this;
   }
 
-  public function amendCommit($message) {
-    $tmp_file = new TempFile();
-    Filesystem::writeFile($tmp_file, $message);
-    $this->execxLocal(
-      'commit --amend --allow-empty -F %s',
-      $tmp_file);
+  public function amendCommit($message = null) {
+    if ($message === null) {
+      $this->execxLocal('commit --amend --allow-empty -C HEAD');
+    } else {
+      $tmp_file = new TempFile();
+      Filesystem::writeFile($tmp_file, $message);
+      $this->execxLocal(
+        'commit --amend --allow-empty -F %s',
+        $tmp_file);
+    }
+
     $this->reloadWorkingCopy();
     return $this;
   }
index 5f9eebb3bd0666abd7ca9985c2359bbf581bead0..da82d3a30ad8aa17906e85033fd14916b1d837b6 100644 (file)
@@ -715,7 +715,11 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
     $this->reloadWorkingCopy();
   }
 
-  public function amendCommit($message) {
+  public function amendCommit($message = null) {
+    if ($message === null) {
+      $message = $this->getCommitMessage('.');
+    }
+
     $tmp_file = new TempFile();
     Filesystem::writeFile($tmp_file, $message);
     $this->execxLocal(
index 5e42918b1cd40499186761a24584709609f698ef..b45184bb23d1ed0a7b34888d2eb7abbfb2268a6c 100644 (file)
@@ -370,7 +370,7 @@ abstract class ArcanistRepositoryAPI {
     throw new ArcanistCapabilityNotSupportedException($this);
   }
 
-  public function amendCommit($message) {
+  public function amendCommit($message = null) {
     throw new ArcanistCapabilityNotSupportedException($this);
   }
 
index 054e409edc3ac0c44e08c059dd63f9d85fdc4e1b..bf2c84e20ec4e44e848cb60a8dfc3e6671ac2040 100644 (file)
@@ -380,6 +380,12 @@ EOTEXT
       $prompt_autofix_patches = true;
     }
 
+    $repository_api = $this->getRepositoryAPI();
+    if ($this->shouldAmendChanges) {
+      $this->shouldAmendChanges = $repository_api->supportsAmend() &&
+        !$this->isHistoryImmutable();
+    }
+
     $wrote_to_disk = false;
 
     switch ($this->getArgument('output')) {
@@ -461,11 +467,7 @@ EOTEXT
       }
     }
 
-    $repository_api = $this->getRepositoryAPI();
-    if ($wrote_to_disk &&
-        ($repository_api instanceof ArcanistGitAPI) &&
-        $this->shouldAmendChanges) {
-
+    if ($wrote_to_disk && $this->shouldAmendChanges) {
       if ($this->shouldAmendWithoutPrompt ||
           ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {
         $console->writeOut(
@@ -477,9 +479,12 @@ EOTEXT
       }
 
       if ($amend) {
-        execx(
-          '(cd %s; git commit -a --amend -C HEAD)',
-          $repository_api->getPath());
+        if ($repository_api instanceof ArcanistGitAPI) {
+          // Add the changes to the index before amending
+          $repository_api->execxLocal('add -A');
+        }
+
+        $repository_api->amendCommit();
       } else {
         throw new ArcanistUsageException(
           "Sort out the lint changes that were applied to the working ".