return $this->status;
}
- public function amendGitHeadCommit($message) {
+ public function amendCommit($message) {
$tmp_file = new TempFile();
Filesystem::writeFile($tmp_file, $message);
$this->execxLocal(
return rtrim($stdout, "\n");
}
+ public function isHistoryDefaultImmutable() {
+ return false;
+ }
+
+ public function supportsAmend() {
+ return true;
+ }
+
public function supportsRelativeLocalCommits() {
return true;
}
return $this->workingCopyRevision;
}
+ public function isHistoryDefaultImmutable() {
+ return true;
+ }
+
+ public function supportsAmend() {
+ list ($err, $stdout) = $this->execManualLocal('help commit');
+ if ($err) {
+ return false;
+ } else {
+ return (strstr($stdout, "amend") !== false);
+ }
+ }
+
public function supportsRelativeLocalCommits() {
return true;
}
public function getCommitMessageLog() {
list($stdout) = $this->execxLocal(
- "log --template '{node}\\1{desc}\\0' --rev %s..%s --",
+ "log --template '{node}\\1{desc}\\0' --prune %s --rev %s --",
$this->getRelativeCommit(),
- $this->getWorkingCopyRevision());
+ "ancestors({$this->getWorkingCopyRevision()})");
$map = array();
ConduitClient $conduit,
array $query) {
+ $messages = $this->getCommitMessageLog();
+ $parser = new ArcanistDiffParser();
+
+ // First, try to find revisions by explicit revision IDs in commit messages.
+ $reason_map = array();
+ $revision_ids = array();
+ foreach ($messages as $node_id => $message) {
+ $object = ArcanistDifferentialCommitMessage::newFromRawCorpus($message);
+
+ if ($object->getRevisionID()) {
+ $revision_ids[] = $object->getRevisionID();
+ $reason_map[$object->getRevisionID()] = $node_id;
+ }
+ }
+
+ if ($revision_ids) {
+ $results = $conduit->callMethodSynchronous(
+ 'differential.query',
+ $query + array(
+ 'ids' => $revision_ids,
+ ));
+
+ foreach ($results as $key => $result) {
+ $hash = substr($reason_map[$result['id']], 0, 16);
+ $results[$key]['why'] =
+ "Commit message for '{$hash}' has explicit 'Differential Revision'.";
+ }
+
+ return $results;
+ }
+
// Try to find revisions by hash.
$hashes = array();
foreach ($this->getLocalCommitInformation() as $commit) {
$this->execxLocal('up');
}
+ public function amendCommit($message) {
+ $tmp_file = new TempFile();
+ Filesystem::writeFile($tmp_file, $message);
+ $this->execxLocal(
+ 'commit --amend -l %s',
+ $tmp_file);
+ }
+
public function setIncludeDirectoryStateInDiffs($include) {
$this->includeDirectoryStateInDiffs = $include;
return $this;
abstract public function getLocalCommitInformation();
abstract public function getSourceControlBaseRevision();
abstract public function getCanonicalRevisionName($string);
+ abstract public function isHistoryDefaultImmutable();
+ abstract public function supportsAmend();
abstract public function supportsRelativeLocalCommits();
abstract public function getWorkingCopyRevision();
abstract public function updateWorkingCopy();
ConduitClient $conduit,
array $query);
+ public function amendCommit() {
+ throw new ArcanistCapabilityNotSupportedException($this);
+ }
+
public function getAllBranches() {
// TODO: Implement for Mercurial/SVN and make abstract.
return array();
return null;
}
+ public function isHistoryDefaultImmutable() {
+ return true;
+ }
+
+ public function supportsAmend() {
+ return false;
+ }
+
public function supportsRelativeLocalCommits() {
return false;
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
- Supports: git
+ Supports: git, hg
Amend the working copy after a revision has been accepted, so commits
can be marked 'committed' and pushed upstream.
+
+ Supported in Mercurial 2.2 and newer.
EOTEXT
);
}
$is_show = $this->getArgument('show');
$repository_api = $this->getRepositoryAPI();
- if (!($repository_api instanceof ArcanistGitAPI)) {
- throw new ArcanistUsageException(
- "You may only run 'arc amend' in a git working copy.");
- }
-
if (!$is_show) {
+ if (!$repository_api->supportsAmend()) {
+ throw new ArcanistUsageException(
+ "You may only run 'arc amend' in a git or hg (version ".
+ "2.2 or newer) working copy.");
+ }
+
if ($this->isHistoryImmutable()) {
throw new ArcanistUsageException(
"This project is marked as adhering to a conservative history ".
echo phutil_console_format(
"Amending commit message to reflect revision **%s**.\n",
"D{$revision_id}: {$revision_title}");
- $repository_api->amendGitHeadCommit($message);
+
+ $repository_api->amendCommit($message);
$mark_workflow = $this->buildChildWorkflow(
'close-revision',
protected function getSupportedRevisionControlSystems() {
- return array('git');
+ return array('git', 'hg');
}
}
}
protected function isHistoryImmutable() {
+ $repository_api = $this->getRepositoryAPI();
$working_copy = $this->getWorkingCopy();
- return ($working_copy->getConfig('immutable_history') === true);
+
+ $project_config = $working_copy->getConfig('immutable_history');
+ if ($project_config !== null) {
+ return $project_config;
+ }
+
+ return $repository_api->isHistoryDefaultImmutable();
}
/**
'revision_id' => $result['revisionid'],
));
- if (!$this->isRawDiffSource()) {
+ if (!$this->isRawDiffSource() && $this->shouldAmend()) {
$repository_api = $this->getRepositoryAPI();
- if (($repository_api instanceof ArcanistGitAPI) &&
- $this->shouldAmend()) {
+
+ if ($repository_api->supportsAmend()) {
echo "Updating commit message...\n";
- $repository_api->amendGitHeadCommit($revised_message);
+ $repository_api->amendCommit($revised_message);
+ } else {
+ echo "Commit message was not amended. Amending commit message is ".
+ "only supported in git and hg (version 2.2 or newer)";
}
}