2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Updates git commit messages after a revision is "Accepted".
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2012-01-31 21:07:05 +01:00
|
|
|
final class ArcanistAmendWorkflow extends ArcanistBaseWorkflow {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'amend';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-01-10 00:22:25 +01:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**amend** [--revision __revision_id__] [--show]
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-06-04 21:30:50 +02:00
|
|
|
Supports: git, hg
|
2011-01-10 00:22:25 +01:00
|
|
|
Amend the working copy after a revision has been accepted, so commits
|
|
|
|
can be marked 'committed' and pushed upstream.
|
2012-06-04 21:30:50 +02:00
|
|
|
|
|
|
|
Supported in Mercurial 2.2 and newer.
|
2011-01-10 00:22:25 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'show' => array(
|
|
|
|
'help' =>
|
2011-10-23 21:55:43 +02:00
|
|
|
"Show the amended commit message, without modifying the working copy."
|
2011-01-10 00:22:25 +01:00
|
|
|
),
|
|
|
|
'revision' => array(
|
|
|
|
'param' => 'revision_id',
|
|
|
|
'help' =>
|
|
|
|
"Amend a specific revision. If you do not specify a revision, ".
|
|
|
|
"arc will look in the commit message at HEAD.",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
2011-10-23 21:55:43 +02:00
|
|
|
$is_show = $this->getArgument('show');
|
2011-08-26 02:53:59 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
2011-10-23 21:55:43 +02:00
|
|
|
if (!$is_show) {
|
2012-06-04 21:30:50 +02:00
|
|
|
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.");
|
|
|
|
}
|
|
|
|
|
2011-10-23 21:55:43 +02:00
|
|
|
if ($this->isHistoryImmutable()) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"This project is marked as adhering to a conservative history ".
|
|
|
|
"mutability doctrine (having an immutable local history), which ".
|
|
|
|
"precludes amending commit messages. You can use 'arc merge' to ".
|
|
|
|
"merge feature branches instead.");
|
|
|
|
}
|
|
|
|
if ($repository_api->getUncommittedChanges()) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"You have uncommitted changes in this branch. Stage and commit (or ".
|
|
|
|
"revert) them before proceeding.");
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2012-01-25 20:40:22 +01:00
|
|
|
$revision_id = null;
|
2011-01-10 00:22:25 +01:00
|
|
|
if ($this->getArgument('revision')) {
|
2011-12-13 20:38:45 +01:00
|
|
|
$revision_id = $this->normalizeRevisionID($this->getArgument('revision'));
|
2012-01-25 20:40:22 +01:00
|
|
|
}
|
|
|
|
|
2012-12-17 21:53:38 +01:00
|
|
|
$repository_api->setBaseCommitArgumentRules('arc:this');
|
2012-01-25 20:40:22 +01:00
|
|
|
$in_working_copy = $repository_api->loadWorkingCopyDifferentialRevisions(
|
|
|
|
$this->getConduit(),
|
|
|
|
array(
|
|
|
|
'authors' => array($this->getUserPHID()),
|
|
|
|
'status' => 'status-any',
|
|
|
|
));
|
|
|
|
$in_working_copy = ipull($in_working_copy, null, 'id');
|
|
|
|
|
|
|
|
if (!$revision_id) {
|
|
|
|
if (count($in_working_copy) == 0) {
|
2011-01-10 00:22:25 +01:00
|
|
|
throw new ArcanistUsageException(
|
2012-01-25 20:40:22 +01:00
|
|
|
"No revision specified with '--revision', and no revisions found ".
|
|
|
|
"in the working copy. Use '--revision <id>' to specify which ".
|
|
|
|
"revision you want to amend.");
|
|
|
|
} else if (count($in_working_copy) > 1) {
|
2012-01-27 02:40:49 +01:00
|
|
|
$message = "More than one revision was found in the working copy:\n".
|
2012-01-25 20:40:22 +01:00
|
|
|
$this->renderRevisionList($in_working_copy)."\n".
|
|
|
|
"Use '--revision <id>' to specify which revision you want to ".
|
|
|
|
"amend.";
|
|
|
|
throw new ArcanistUsageException($message);
|
|
|
|
} else {
|
|
|
|
$revision_id = key($in_working_copy);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$conduit = $this->getConduit();
|
2011-12-13 20:38:45 +01:00
|
|
|
try {
|
|
|
|
$message = $conduit->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => $revision_id,
|
|
|
|
'edit' => false,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} catch (ConduitClientException $ex) {
|
|
|
|
if (strpos($ex->getMessage(), 'ERR_NOT_FOUND') === false) {
|
|
|
|
throw $ex;
|
|
|
|
} else {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Revision D{$revision_id} does not exist."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2012-01-25 20:40:22 +01:00
|
|
|
$revision = $conduit->callMethodSynchronous(
|
|
|
|
'differential.query',
|
|
|
|
array(
|
|
|
|
'ids' => array($revision_id),
|
|
|
|
));
|
|
|
|
if (empty($revision)) {
|
|
|
|
throw new Exception(
|
|
|
|
"Failed to lookup information for 'D{$revision_id}'!");
|
|
|
|
}
|
|
|
|
$revision = head($revision);
|
|
|
|
$revision_title = $revision['title'];
|
|
|
|
|
|
|
|
if (!$is_show) {
|
|
|
|
if ($revision_id && empty($in_working_copy[$revision_id])) {
|
|
|
|
$ok = phutil_console_confirm(
|
|
|
|
"The revision 'D{$revision_id}' does not appear to be in the ".
|
|
|
|
"working copy. Are you sure you want to amend HEAD with the ".
|
|
|
|
"commit message for 'D{$revision_id}: {$revision_title}'?");
|
|
|
|
if (!$ok) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-23 21:55:43 +02:00
|
|
|
if ($is_show) {
|
2011-01-10 00:22:25 +01:00
|
|
|
echo $message."\n";
|
|
|
|
} else {
|
2012-01-25 20:40:22 +01:00
|
|
|
echo phutil_console_format(
|
|
|
|
"Amending commit message to reflect revision **%s**.\n",
|
|
|
|
"D{$revision_id}: {$revision_title}");
|
2012-06-04 21:30:50 +02:00
|
|
|
|
|
|
|
$repository_api->amendCommit($message);
|
2011-01-10 00:51:04 +01:00
|
|
|
|
Automatically detect when to mark revisions committed
Summary:
See D945. We have this kludgy "remote_hooks_installed" mess right now, but we
have enough information on the server nowadays to figure this out without it.
Also reduce code duplication by sharing the "mark-committed" workflow.
This causes "arc merge" to effect commit marks.
Test Plan:
In Git, Mercurial and SVN working copies ran like a million
amend/merge/commit/mark-committed commands with and without --finalize in
various states of revision completion.
This change is really hard to exhaustively test because of the number of
combinations of VCS, revision state, command, command flags, repository state
and tracking state. All the reasonable tests I could come up with worked
correctly, though.
Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 967
2011-09-27 18:37:11 +02:00
|
|
|
$mark_workflow = $this->buildChildWorkflow(
|
2012-04-17 22:51:10 +02:00
|
|
|
'close-revision',
|
Automatically detect when to mark revisions committed
Summary:
See D945. We have this kludgy "remote_hooks_installed" mess right now, but we
have enough information on the server nowadays to figure this out without it.
Also reduce code duplication by sharing the "mark-committed" workflow.
This causes "arc merge" to effect commit marks.
Test Plan:
In Git, Mercurial and SVN working copies ran like a million
amend/merge/commit/mark-committed commands with and without --finalize in
various states of revision completion.
This change is really hard to exhaustively test because of the number of
combinations of VCS, revision state, command, command flags, repository state
and tracking state. All the reasonable tests I could come up with worked
correctly, though.
Reviewers: Makinde, jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 967
2011-09-27 18:37:11 +02:00
|
|
|
array(
|
|
|
|
'--finalize',
|
|
|
|
$revision_id,
|
|
|
|
));
|
|
|
|
$mark_workflow->run();
|
2011-02-17 03:49:45 +01:00
|
|
|
}
|
2011-02-17 03:47:17 +01:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2011-01-15 05:00:11 +01:00
|
|
|
|
2012-01-25 20:40:22 +01:00
|
|
|
|
2011-01-15 05:00:11 +01:00
|
|
|
protected function getSupportedRevisionControlSystems() {
|
2012-06-04 21:30:50 +02:00
|
|
|
return array('git', 'hg');
|
2011-01-15 05:00:11 +01:00
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|