4
* Show which revision or revisions are in the working copy.
6
final class ArcanistWhichWorkflow extends ArcanistWorkflow {
8
public function getWorkflowName() {
12
public function getCommandSynopses() {
13
return phutil_console_format(<<<EOTEXT
14
**which** [options] (svn)
15
**which** [options] [__commit__] (hg, git)
20
public function getCommandHelp() {
21
return phutil_console_format(<<<EOTEXT
22
Supports: svn, git, hg
23
Shows which repository the current working copy corresponds to,
24
which commits 'arc diff' will select, and which revision is in
25
the working copy (or which revisions, if more than one matches).
30
public function requiresConduit() {
34
public function requiresRepositoryAPI() {
38
public function requiresAuthentication() {
42
public function getArguments() {
44
'any-status' => array(
45
'help' => 'Show committed and abandoned revisions.',
49
'help' => 'Additional rules for determining base revision.',
51
'svn' => 'Subversion does not use base commits.',
53
'supports' => array('git', 'hg'),
56
'help' => 'Print base commit only and exit.',
58
'svn' => 'Subversion does not use base commits.',
60
'supports' => array('git', 'hg'),
64
'help' => pht('Specify the end of the commit range to select.'),
66
'svn' => pht('Subversion does not support commit ranges.'),
67
'hg' => pht('Mercurial does not support --head yet.'),
69
'supports' => array('git'),
75
public function run() {
76
$console = PhutilConsole::getConsole();
78
$this->printRepositorySection();
79
$console->writeOut("\n");
81
$repository_api = $this->getRepositoryAPI();
83
$arg_commit = $this->getArgument('commit');
84
if (count($arg_commit)) {
85
$this->parseBaseCommitArgument($arg_commit);
87
$arg = $arg_commit ? ' '.head($arg_commit) : '';
89
$repository_api->setBaseCommitArgumentRules(
90
$this->getArgument('base', ''));
92
$supports_ranges = $repository_api->supportsCommitRanges();
94
$head_commit = $this->getArgument('head');
95
if ($head_commit !== null) {
96
$arg .= csprintf(' --head %R', $head_commit);
97
$repository_api->setHeadCommit($head_commit);
100
if ($supports_ranges) {
101
$relative = $repository_api->getBaseCommit();
103
if ($this->getArgument('show-base')) {
108
$info = $repository_api->getLocalCommitInformation();
111
foreach ($info as $commit) {
112
$hash = substr($commit['commit'], 0, 16);
113
$summary = $commit['summary'];
115
$commits[] = " {$hash} {$summary}";
117
$commits = implode("\n", $commits);
119
$commits = ' (No commits.)';
122
$explanation = $repository_api->getBaseCommitExplanation();
124
$relative_summary = $repository_api->getCommitSummary($relative);
125
$relative = substr($relative, 0, 16);
127
if ($repository_api instanceof ArcanistGitAPI) {
128
$head = $this->getArgument('head', 'HEAD');
129
$command = csprintf('git diff %R', "{$relative}..{$head}");
130
} else if ($repository_api instanceof ArcanistMercurialAPI) {
133
hgsprintf('%s', $relative));
135
throw new Exception('Unknown VCS!');
138
echo phutil_console_wrap(
139
phutil_console_format(
140
"**COMMIT RANGE**\n".
141
"If you run 'arc diff{$arg}', changes between the commit:\n\n"));
143
echo " {$relative} {$relative_summary}\n\n";
145
if ($head_commit === null) {
147
'...and the current working copy state will be sent to '.
148
'Differential, because %s',
152
'...and "%s" will be sent to Differential, because %s',
157
echo phutil_console_wrap(
158
"{$will_be_sent}\n\n".
159
"You can see the exact changes that will be sent by running ".
162
"These commits will be included in the diff:\n\n");
164
echo $commits."\n\n\n";
167
$any_status = $this->getArgument('any-status');
170
'status' => $any_status
175
$revisions = $repository_api->loadWorkingCopyDifferentialRevisions(
179
echo phutil_console_wrap(
180
phutil_console_format(
181
"**MATCHING REVISIONS**\n".
182
"These Differential revisions match the changes in this working ".
185
if (empty($revisions)) {
186
echo " (No revisions match.)\n";
188
echo phutil_console_wrap(
189
phutil_console_format(
190
"Since there are no revisions in Differential which match this ".
191
"working copy, a new revision will be **created** if you run ".
192
"'arc diff{$arg}'.\n\n"));
194
$other_author_phids = array();
195
foreach ($revisions as $revision) {
196
if ($revision['authorPHID'] != $this->getUserPHID()) {
197
$other_author_phids[] = $revision['authorPHID'];
201
$other_authors = array();
202
if ($other_author_phids) {
203
$other_authors = $this->getConduit()->callMethodSynchronous(
206
'phids' => $other_author_phids,
208
$other_authors = ipull($other_authors, 'userName', 'phid');
211
foreach ($revisions as $revision) {
212
$title = $revision['title'];
213
$monogram = 'D'.$revision['id'];
215
if ($revision['authorPHID'] != $this->getUserPHID()) {
216
$author = $other_authors[$revision['authorPHID']];
217
echo pht(" %s (%s) %s\n", $monogram, $author, $title);
219
echo pht(" %s %s\n", $monogram, $title);
222
echo ' Reason: '.$revision['why']."\n";
225
if (count($revisions) == 1) {
226
echo phutil_console_wrap(
227
phutil_console_format(
228
"Since exactly one revision in Differential matches this working ".
229
"copy, it will be **updated** if you run 'arc diff{$arg}'."));
231
echo phutil_console_wrap(
232
"Since more than one revision in Differential matches this working ".
233
"copy, you will be asked which revision you want to update if ".
234
"you run 'arc diff {$arg}'.");
242
private function printRepositorySection() {
243
$console = PhutilConsole::getConsole();
244
$console->writeOut("**%s**\n", pht('REPOSITORY'));
246
$callsign = $this->getRepositoryCallsign();
251
'To identify the repository associated with this working copy, '.
252
'arc followed this process:'));
254
foreach ($this->getRepositoryReasons() as $reason) {
255
$reason = phutil_console_wrap($reason, 4);
256
$console->writeOut("%s\n\n", $reason);
262
pht('This working copy is associated with the %s repository.',
263
phutil_console_format('**%s**', $callsign)));
267
pht('This working copy is not associated with any repository.'));