2012-01-24 08:07:38 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show which revision or revisions are in the working copy.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2012-01-31 12:07:05 -08:00
|
|
|
final class ArcanistWhichWorkflow extends ArcanistBaseWorkflow {
|
2012-01-24 08:07:38 -08: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 08:35:03 -07:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'which';
|
|
|
|
}
|
|
|
|
|
2012-03-05 10:02:37 -08:00
|
|
|
public function getCommandSynopses() {
|
2012-01-24 08:07:38 -08:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**which** (svn)
|
|
|
|
**which** [commit] (hg, git)
|
2012-03-05 10:02:37 -08:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-01-24 08:07:38 -08:00
|
|
|
Supports: svn, git, hg
|
Allow `arc` to identify repositories without "project_id"
Summary:
Ref T4343. Continues the process of reducing the prominence of Arcanist Projects. Primarily:
- Query Phabricator to identify the working copy based on explicit configuration, or guess based on heuristics.
- Enhance `arc which` to explain the process to the user.
- The `project_id` key is no longer required in `.arcconfig`.
Minor/cleanup changes:
- Rename `project_id` to `project.name` (consistency, clarity).
- Rename `conduit_uri` to `phabricator.uri` (consistency, clairty).
- These both need documentation updates.
- Add `repository.callsign` to explicitly bind to a repository.
- Updated `.arcconfig` for the new values.
- Fix a unit test which broke a while ago when we fixed a rare definition of "unstaged".
- Make `getRepositoryUUID()` generic so we can get rid of one `instanceof`.
Test Plan:
- Ran `arc which`.
- Ran `arc diff`.
- This doesn't really change anything, so the only real risk is version compatibility breaks. This //does// introduce such a break, but the window is very narrow: if you upgrade `arc` after this commit, and try to diff against a Phabricator which was updated after yesterday (D8068) but before D8072 lands, the lookup will work so we'll add `repositoryPHID` to the `differential.creatediff` call, but it won't exist in Phabricator yet. This window is so narrow that I'm not going to try to fix it, as I'd guess there is a significant chance that no users will be affected. I don't see a clever way to fix it that doesn't involve a lot of work, either.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4343
Differential Revision: https://secure.phabricator.com/D8073
2014-01-26 15:31:30 -08:00
|
|
|
Shows which repository the current working copy corresponds to,
|
|
|
|
which commits 'arc diff' will select, and which revision is in
|
2012-05-11 06:07:33 -07:00
|
|
|
the working copy (or which revisions, if more than one matches).
|
2012-01-24 08:07:38 -08:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'any-author' => array(
|
|
|
|
'help' => "Show revisions by any author, not just you.",
|
|
|
|
),
|
|
|
|
'any-status' => array(
|
|
|
|
'help' => "Show committed and abandoned revisions.",
|
|
|
|
),
|
Add a DSL for selecting base commits
Summary:
New optional mode. If you set 'base' in local, project or global config or pass '--base' to 'arc diff' or 'arc which', it switches to DSL mode.
In DSL mode, lists of rules from args, local, project and global config are resolved, in that order. Rules can manipulate the rule machine or resolve into actual commits. Provides support for some 'arc' rules (mostly machine manipulation) and 'git' rules (symbolic ref and merge-base).
Test Plan:
Ran unit tests. Also:
```$ arc which --show-base --base 'arc:prompt'
Against which commit? HEAD
HEAD
$ arc which --show-base --base 'git:HEAD'
HEAD
$ arc which --show-base --base 'git:fake'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'git:origin/master'
origin/master
$ arc which --show-base --base 'git:upstream'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'literal:derp'
derp
$ arc which --show-base --base 'arc:halt'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc set-config --local base git:origin/master
Set key 'base' = 'git:origin/master' in local config.
$ arc which --show-base
origin/master
$ arc which --show-base --base 'git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:yield, git:HEAD^'
origin/master
$ arc which --show-base --base 'arc:global, git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:global, git:merge-base(origin/master)'
3f4f8992fba8d1f142974da36a82bae900e247c0```
Reviewers: dschleimer, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1233
Differential Revision: https://secure.phabricator.com/D2748
2012-06-15 14:01:28 -07:00
|
|
|
'base' => array(
|
|
|
|
'param' => 'rules',
|
|
|
|
'help' => 'Additional rules for determining base revision.',
|
|
|
|
'nosupport' => array(
|
|
|
|
'svn' => 'Subversion does not use base commits.',
|
|
|
|
),
|
|
|
|
'supports' => array('git', 'hg'),
|
|
|
|
),
|
|
|
|
'show-base' => array(
|
|
|
|
'help' => 'Print base commit only and exit.',
|
|
|
|
'nosupport' => array(
|
|
|
|
'svn' => 'Subversion does not use base commits.',
|
|
|
|
),
|
|
|
|
'supports' => array('git', 'hg'),
|
|
|
|
),
|
2012-01-24 08:07:38 -08:00
|
|
|
'*' => 'commit',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
|
Allow `arc` to identify repositories without "project_id"
Summary:
Ref T4343. Continues the process of reducing the prominence of Arcanist Projects. Primarily:
- Query Phabricator to identify the working copy based on explicit configuration, or guess based on heuristics.
- Enhance `arc which` to explain the process to the user.
- The `project_id` key is no longer required in `.arcconfig`.
Minor/cleanup changes:
- Rename `project_id` to `project.name` (consistency, clarity).
- Rename `conduit_uri` to `phabricator.uri` (consistency, clairty).
- These both need documentation updates.
- Add `repository.callsign` to explicitly bind to a repository.
- Updated `.arcconfig` for the new values.
- Fix a unit test which broke a while ago when we fixed a rare definition of "unstaged".
- Make `getRepositoryUUID()` generic so we can get rid of one `instanceof`.
Test Plan:
- Ran `arc which`.
- Ran `arc diff`.
- This doesn't really change anything, so the only real risk is version compatibility breaks. This //does// introduce such a break, but the window is very narrow: if you upgrade `arc` after this commit, and try to diff against a Phabricator which was updated after yesterday (D8068) but before D8072 lands, the lookup will work so we'll add `repositoryPHID` to the `differential.creatediff` call, but it won't exist in Phabricator yet. This window is so narrow that I'm not going to try to fix it, as I'd guess there is a significant chance that no users will be affected. I don't see a clever way to fix it that doesn't involve a lot of work, either.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4343
Differential Revision: https://secure.phabricator.com/D8073
2014-01-26 15:31:30 -08:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
|
|
|
$this->printRepositorySection();
|
|
|
|
$console->writeOut("\n");
|
|
|
|
|
2012-01-24 08:07:38 -08:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
2012-05-11 06:07:33 -07:00
|
|
|
$arg_commit = $this->getArgument('commit');
|
|
|
|
if (count($arg_commit)) {
|
2012-12-17 12:54:08 -08:00
|
|
|
$this->parseBaseCommitArgument($arg_commit);
|
2012-01-24 08:07:38 -08:00
|
|
|
}
|
2012-05-11 06:07:33 -07:00
|
|
|
$arg = $arg_commit ? ' '.head($arg_commit) : '';
|
|
|
|
|
Add a DSL for selecting base commits
Summary:
New optional mode. If you set 'base' in local, project or global config or pass '--base' to 'arc diff' or 'arc which', it switches to DSL mode.
In DSL mode, lists of rules from args, local, project and global config are resolved, in that order. Rules can manipulate the rule machine or resolve into actual commits. Provides support for some 'arc' rules (mostly machine manipulation) and 'git' rules (symbolic ref and merge-base).
Test Plan:
Ran unit tests. Also:
```$ arc which --show-base --base 'arc:prompt'
Against which commit? HEAD
HEAD
$ arc which --show-base --base 'git:HEAD'
HEAD
$ arc which --show-base --base 'git:fake'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'git:origin/master'
origin/master
$ arc which --show-base --base 'git:upstream'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'literal:derp'
derp
$ arc which --show-base --base 'arc:halt'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc set-config --local base git:origin/master
Set key 'base' = 'git:origin/master' in local config.
$ arc which --show-base
origin/master
$ arc which --show-base --base 'git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:yield, git:HEAD^'
origin/master
$ arc which --show-base --base 'arc:global, git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:global, git:merge-base(origin/master)'
3f4f8992fba8d1f142974da36a82bae900e247c0```
Reviewers: dschleimer, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1233
Differential Revision: https://secure.phabricator.com/D2748
2012-06-15 14:01:28 -07:00
|
|
|
$repository_api->setBaseCommitArgumentRules(
|
|
|
|
$this->getArgument('base', ''));
|
|
|
|
|
2012-12-17 12:54:08 -08:00
|
|
|
if ($repository_api->supportsCommitRanges()) {
|
|
|
|
$relative = $repository_api->getBaseCommit();
|
2012-05-11 06:07:33 -07:00
|
|
|
|
Add a DSL for selecting base commits
Summary:
New optional mode. If you set 'base' in local, project or global config or pass '--base' to 'arc diff' or 'arc which', it switches to DSL mode.
In DSL mode, lists of rules from args, local, project and global config are resolved, in that order. Rules can manipulate the rule machine or resolve into actual commits. Provides support for some 'arc' rules (mostly machine manipulation) and 'git' rules (symbolic ref and merge-base).
Test Plan:
Ran unit tests. Also:
```$ arc which --show-base --base 'arc:prompt'
Against which commit? HEAD
HEAD
$ arc which --show-base --base 'git:HEAD'
HEAD
$ arc which --show-base --base 'git:fake'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'git:origin/master'
origin/master
$ arc which --show-base --base 'git:upstream'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc which --show-base --base 'literal:derp'
derp
$ arc which --show-base --base 'arc:halt'
Usage Exception: None of the rules in your 'base' configuration matched a valid commit. Adjust rules or specify which commit you want to use explicitly.
$ arc set-config --local base git:origin/master
Set key 'base' = 'git:origin/master' in local config.
$ arc which --show-base
origin/master
$ arc which --show-base --base 'git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:yield, git:HEAD^'
origin/master
$ arc which --show-base --base 'arc:global, git:HEAD^'
HEAD^
$ arc which --show-base --base 'arc:global, git:merge-base(origin/master)'
3f4f8992fba8d1f142974da36a82bae900e247c0```
Reviewers: dschleimer, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1233
Differential Revision: https://secure.phabricator.com/D2748
2012-06-15 14:01:28 -07:00
|
|
|
if ($this->getArgument('show-base')) {
|
|
|
|
echo $relative."\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-11 06:07:33 -07:00
|
|
|
$info = $repository_api->getLocalCommitInformation();
|
|
|
|
if ($info) {
|
|
|
|
$commits = array();
|
|
|
|
foreach ($info as $commit) {
|
|
|
|
$hash = substr($commit['commit'], 0, 16);
|
|
|
|
$summary = $commit['summary'];
|
|
|
|
|
|
|
|
$commits[] = " {$hash} {$summary}";
|
|
|
|
}
|
|
|
|
$commits = implode("\n", $commits);
|
|
|
|
} else {
|
|
|
|
$commits = ' (No commits.)';
|
|
|
|
}
|
|
|
|
|
2012-06-14 12:02:41 -07:00
|
|
|
$explanation = $repository_api->getBaseCommitExplanation();
|
2012-05-11 06:07:33 -07:00
|
|
|
|
|
|
|
$relative_summary = $repository_api->getCommitSummary($relative);
|
|
|
|
$relative = substr($relative, 0, 16);
|
|
|
|
|
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
$command = "git diff {$relative}..HEAD";
|
|
|
|
} else if ($repository_api instanceof ArcanistMercurialAPI) {
|
Fix some arc/mercurial issues
Summary:
- In "arc which", we recommend "--rev x --rev ." to show changes. This is not accurate if there are uncommitted changes in the working copy. Just "--rev x" shows the correct changes (implicitly, the other end of the range is the working copy state).
- When you diff only working copy changes, we currently incorrectly identify all your open revisions as belonging to the working copy. Instead, correctly identify none of them as belonging to the working copy (in theory, we could go farther than this and do path-based identification like SVN, but with --amend in hg 2.2+ this workflow should be going away in the long run).
- If you have uncommitted working copy changes, never try to amend.
Test Plan: Ran "arc which .", "arc diff ." in a working copy with dirty changes, got better results than before.
Reviewers: dschleimer, btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1507
Differential Revision: https://secure.phabricator.com/D2980
2012-07-17 16:16:11 -07:00
|
|
|
$command = "hg diff --rev {$relative}";
|
2012-05-11 06:07:33 -07:00
|
|
|
} else {
|
|
|
|
throw new Exception("Unknown VCS!");
|
|
|
|
}
|
|
|
|
|
|
|
|
echo phutil_console_wrap(
|
|
|
|
phutil_console_format(
|
|
|
|
"**RELATIVE COMMIT**\n".
|
|
|
|
"If you run 'arc diff{$arg}', changes between the commit:\n\n"));
|
|
|
|
|
|
|
|
echo " {$relative} {$relative_summary}\n\n";
|
|
|
|
echo phutil_console_wrap(
|
|
|
|
"...and the current working copy state will be sent to ".
|
|
|
|
"Differential, because {$explanation}\n\n".
|
|
|
|
"You can see the exact changes that will be sent by running ".
|
|
|
|
"this command:\n\n".
|
|
|
|
" $ {$command}\n\n".
|
|
|
|
"These commits will be included in the diff:\n\n");
|
|
|
|
|
|
|
|
echo $commits."\n\n\n";
|
|
|
|
}
|
2012-01-24 08:07:38 -08:00
|
|
|
|
|
|
|
$any_author = $this->getArgument('any-author');
|
|
|
|
$any_status = $this->getArgument('any-status');
|
|
|
|
|
|
|
|
$query = array(
|
|
|
|
'authors' => $any_author
|
|
|
|
? null
|
|
|
|
: array($this->getUserPHID()),
|
|
|
|
'status' => $any_status
|
|
|
|
? 'status-any'
|
|
|
|
: 'status-open',
|
|
|
|
);
|
|
|
|
|
|
|
|
$revisions = $repository_api->loadWorkingCopyDifferentialRevisions(
|
|
|
|
$this->getConduit(),
|
|
|
|
$query);
|
|
|
|
|
2012-05-11 06:07:33 -07:00
|
|
|
echo phutil_console_wrap(
|
|
|
|
phutil_console_format(
|
|
|
|
"**MATCHING REVISIONS**\n".
|
|
|
|
"These Differential revisions match the changes in this working ".
|
|
|
|
"copy:\n\n"));
|
2012-01-24 08:07:38 -08:00
|
|
|
|
2012-05-11 06:07:33 -07:00
|
|
|
if (empty($revisions)) {
|
|
|
|
echo " (No revisions match.)\n";
|
|
|
|
echo "\n";
|
|
|
|
echo phutil_console_wrap(
|
|
|
|
phutil_console_format(
|
|
|
|
"Since there are no revisions in Differential which match this ".
|
|
|
|
"working copy, a new revision will be **created** if you run ".
|
|
|
|
"'arc diff{$arg}'.\n\n"));
|
|
|
|
} else {
|
|
|
|
foreach ($revisions as $revision) {
|
|
|
|
echo ' D'.$revision['id'].' '.$revision['title']."\n";
|
|
|
|
echo ' Reason: '.$revision['why']."\n";
|
|
|
|
echo "\n";
|
|
|
|
}
|
2012-01-24 08:07:38 -08:00
|
|
|
if (count($revisions) == 1) {
|
2012-05-11 06:07:33 -07:00
|
|
|
echo phutil_console_wrap(
|
|
|
|
phutil_console_format(
|
|
|
|
"Since exactly one revision in Differential matches this working ".
|
|
|
|
"copy, it will be **updated** if you run 'arc diff{$arg}'."));
|
2012-01-24 08:07:38 -08:00
|
|
|
} else {
|
2012-05-11 06:07:33 -07:00
|
|
|
echo phutil_console_wrap(
|
|
|
|
"Since more than one revision in Differential matches this working ".
|
|
|
|
"copy, you will be asked which revision you want to update if ".
|
|
|
|
"you run 'arc diff {$arg}'.");
|
2012-01-24 08:07:38 -08:00
|
|
|
}
|
2012-05-11 06:07:33 -07:00
|
|
|
echo "\n\n";
|
2012-01-24 08:07:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
Allow `arc` to identify repositories without "project_id"
Summary:
Ref T4343. Continues the process of reducing the prominence of Arcanist Projects. Primarily:
- Query Phabricator to identify the working copy based on explicit configuration, or guess based on heuristics.
- Enhance `arc which` to explain the process to the user.
- The `project_id` key is no longer required in `.arcconfig`.
Minor/cleanup changes:
- Rename `project_id` to `project.name` (consistency, clarity).
- Rename `conduit_uri` to `phabricator.uri` (consistency, clairty).
- These both need documentation updates.
- Add `repository.callsign` to explicitly bind to a repository.
- Updated `.arcconfig` for the new values.
- Fix a unit test which broke a while ago when we fixed a rare definition of "unstaged".
- Make `getRepositoryUUID()` generic so we can get rid of one `instanceof`.
Test Plan:
- Ran `arc which`.
- Ran `arc diff`.
- This doesn't really change anything, so the only real risk is version compatibility breaks. This //does// introduce such a break, but the window is very narrow: if you upgrade `arc` after this commit, and try to diff against a Phabricator which was updated after yesterday (D8068) but before D8072 lands, the lookup will work so we'll add `repositoryPHID` to the `differential.creatediff` call, but it won't exist in Phabricator yet. This window is so narrow that I'm not going to try to fix it, as I'd guess there is a significant chance that no users will be affected. I don't see a clever way to fix it that doesn't involve a lot of work, either.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4343
Differential Revision: https://secure.phabricator.com/D8073
2014-01-26 15:31:30 -08:00
|
|
|
|
|
|
|
private function printRepositorySection() {
|
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
$console->writeOut("**%s**\n", pht('REPOSITORY'));
|
|
|
|
|
|
|
|
$callsign = $this->getRepositoryCallsign();
|
|
|
|
|
|
|
|
$console->writeOut(
|
|
|
|
"%s\n\n",
|
|
|
|
pht(
|
|
|
|
'To identify the repository associated with this working copy, '.
|
|
|
|
'arc followed this process:'));
|
|
|
|
|
|
|
|
foreach ($this->getRepositoryReasons() as $reason) {
|
|
|
|
$reason = phutil_console_wrap($reason, 4);
|
|
|
|
$console->writeOut("%s\n\n", $reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($callsign) {
|
|
|
|
$console->writeOut(
|
|
|
|
"%s\n",
|
|
|
|
pht('This working copy is associated with the %s repository.',
|
|
|
|
phutil_console_format('**%s**', $callsign)));
|
|
|
|
} else {
|
|
|
|
$console->writeOut(
|
|
|
|
"%s\n",
|
|
|
|
pht('This working copy is not associated with any repository.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 08:07:38 -08:00
|
|
|
}
|