1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +01:00

Enable lint amending commits in mercurial

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
This commit is contained in:
durham 2013-04-16 13:32:12 -07:00
parent bfc1eeba07
commit b3108661bb
4 changed files with 30 additions and 16 deletions

View file

@ -514,12 +514,17 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
return $this; return $this;
} }
public function amendCommit($message) { public function amendCommit($message = null) {
$tmp_file = new TempFile(); if ($message === null) {
Filesystem::writeFile($tmp_file, $message); $this->execxLocal('commit --amend --allow-empty -C HEAD');
$this->execxLocal( } else {
'commit --amend --allow-empty -F %s', $tmp_file = new TempFile();
$tmp_file); Filesystem::writeFile($tmp_file, $message);
$this->execxLocal(
'commit --amend --allow-empty -F %s',
$tmp_file);
}
$this->reloadWorkingCopy(); $this->reloadWorkingCopy();
return $this; return $this;
} }

View file

@ -715,7 +715,11 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
$this->reloadWorkingCopy(); $this->reloadWorkingCopy();
} }
public function amendCommit($message) { public function amendCommit($message = null) {
if ($message === null) {
$message = $this->getCommitMessage('.');
}
$tmp_file = new TempFile(); $tmp_file = new TempFile();
Filesystem::writeFile($tmp_file, $message); Filesystem::writeFile($tmp_file, $message);
$this->execxLocal( $this->execxLocal(

View file

@ -370,7 +370,7 @@ abstract class ArcanistRepositoryAPI {
throw new ArcanistCapabilityNotSupportedException($this); throw new ArcanistCapabilityNotSupportedException($this);
} }
public function amendCommit($message) { public function amendCommit($message = null) {
throw new ArcanistCapabilityNotSupportedException($this); throw new ArcanistCapabilityNotSupportedException($this);
} }

View file

@ -380,6 +380,12 @@ EOTEXT
$prompt_autofix_patches = true; $prompt_autofix_patches = true;
} }
$repository_api = $this->getRepositoryAPI();
if ($this->shouldAmendChanges) {
$this->shouldAmendChanges = $repository_api->supportsAmend() &&
!$this->isHistoryImmutable();
}
$wrote_to_disk = false; $wrote_to_disk = false;
switch ($this->getArgument('output')) { switch ($this->getArgument('output')) {
@ -461,11 +467,7 @@ EOTEXT
} }
} }
$repository_api = $this->getRepositoryAPI(); if ($wrote_to_disk && $this->shouldAmendChanges) {
if ($wrote_to_disk &&
($repository_api instanceof ArcanistGitAPI) &&
$this->shouldAmendChanges) {
if ($this->shouldAmendWithoutPrompt || if ($this->shouldAmendWithoutPrompt ||
($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) { ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {
$console->writeOut( $console->writeOut(
@ -477,9 +479,12 @@ EOTEXT
} }
if ($amend) { if ($amend) {
execx( if ($repository_api instanceof ArcanistGitAPI) {
'(cd %s; git commit -a --amend -C HEAD)', // Add the changes to the index before amending
$repository_api->getPath()); $repository_api->execxLocal('add -A');
}
$repository_api->amendCommit();
} else { } else {
throw new ArcanistUsageException( throw new ArcanistUsageException(
"Sort out the lint changes that were applied to the working ". "Sort out the lint changes that were applied to the working ".