2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Updates git commit messages after a revision is "Accepted".
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2011-01-10 00:22:25 +01:00
|
|
|
class ArcanistAmendWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**amend** [--revision __revision_id__] [--show]
|
|
|
|
Supports: git
|
|
|
|
Amend the working copy after a revision has been accepted, so commits
|
|
|
|
can be marked 'committed' and pushed upstream.
|
|
|
|
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();
|
|
|
|
if (!($repository_api instanceof ArcanistGitAPI)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"You may only run 'arc amend' in a git working copy.");
|
|
|
|
}
|
|
|
|
|
2011-10-23 21:55:43 +02:00
|
|
|
if (!$is_show) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getArgument('revision')) {
|
|
|
|
$revision_id = $this->getArgument('revision');
|
|
|
|
} else {
|
|
|
|
$log = $repository_api->getGitCommitLog();
|
|
|
|
$parser = new ArcanistDiffParser();
|
|
|
|
$changes = $parser->parseDiff($log);
|
|
|
|
if (count($changes) != 1) {
|
|
|
|
throw new Exception("Expected one log.");
|
|
|
|
}
|
|
|
|
$change = reset($changes);
|
|
|
|
if ($change->getType() != ArcanistDiffChangeType::TYPE_MESSAGE) {
|
|
|
|
throw new Exception("Expected message change.");
|
|
|
|
}
|
|
|
|
$message = ArcanistDifferentialCommitMessage::newFromRawCorpus(
|
|
|
|
$change->getMetadata('message'));
|
|
|
|
$revision_id = $message->getRevisionID();
|
|
|
|
if (!$revision_id) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"No revision specified with '--revision', and no Differential ".
|
|
|
|
"revision marker in HEAD.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-15 23:57:24 +01:00
|
|
|
// TODO: The old 'arc amend' had a check here to see if you were running
|
|
|
|
// 'arc amend' with an explicit revision but HEAD already had another
|
|
|
|
// revision in it. Maybe this is worth restoring?
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$conduit = $this->getConduit();
|
|
|
|
$message = $conduit->callMethodSynchronous(
|
|
|
|
'differential.getcommitmessage',
|
|
|
|
array(
|
|
|
|
'revision_id' => $revision_id,
|
2011-05-03 03:54:20 +02:00
|
|
|
'edit' => false,
|
2011-01-10 00:22:25 +01:00
|
|
|
));
|
|
|
|
|
2011-10-23 21:55:43 +02:00
|
|
|
if ($is_show) {
|
2011-01-10 00:22:25 +01:00
|
|
|
echo $message."\n";
|
|
|
|
} else {
|
|
|
|
$repository_api->amendGitHeadCommit($message);
|
|
|
|
echo "Amended commit message.\n";
|
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(
|
|
|
|
'mark-committed',
|
|
|
|
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
|
|
|
|
|
|
|
protected function getSupportedRevisionControlSystems() {
|
|
|
|
return array('git');
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|