1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-09 16:32:39 +01:00

Push to staging areas when running "arc diff"

Summary: Ref T8238. If a staging area is configured for a repository (see D13019), push a copy of changes to it after creating a diff.

Test Plan: Ran `arc diff` with various options, saw applicable changes get pushed to staging.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: cburroughs, epriestley

Maniphest Tasks: T8238

Differential Revision: https://secure.phabricator.com/D13020
This commit is contained in:
epriestley 2015-05-27 10:27:03 -07:00
parent a36dc81715
commit 3ac80200e2
2 changed files with 115 additions and 0 deletions

View file

@ -370,6 +370,9 @@ EOTEXT
'skip-binaries' => array(
'help' => pht('Do not upload binaries (like images).'),
),
'skip-staging' => array(
'help' => pht('Do not copy changes to the staging area.'),
),
'ignore-unsound-tests' => array(
'help' => pht('Ignore unsound test failures without prompting.'),
),
@ -517,6 +520,8 @@ EOTEXT
'unitResult' => $unit_result,
));
$this->pushChangesToStagingArea($this->diffID);
$this->updateLintDiffProperty();
$this->updateUnitDiffProperty();
$this->updateLocalDiffProperty();
@ -2604,4 +2609,85 @@ EOTEXT
return $this->getArgument('browse');
}
private function pushChangesToStagingArea($id) {
if ($this->getArgument('skip-staging')) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('Flag --skip-staging was specified.'));
return;
}
if ($this->isRawDiffSource()) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('Raw changes can not be pushed to a staging area.'));
return;
}
if (!$this->getRepositoryPHID()) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('Unable to determine repository for this change.'));
return;
}
$staging = $this->getRepositoryStagingConfiguration();
if ($staging === null) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('The server does not support staging areas.'));
return;
}
$supported = idx($staging, 'supported');
if (!$supported) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('Phabricator does not support staging areas for this repository.'));
return;
}
$staging_uri = idx($staging, 'uri');
if (!$staging_uri) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('No staging area is configured for this repository.'));
return;
}
$api = $this->getRepositoryAPI();
if (!($api instanceof ArcanistGitAPI)) {
$this->writeInfo(
pht('SKIP STAGING'),
pht('This client version does not support staging this repository.'));
return;
}
$commit = $api->getHeadCommit();
$prefix = idx($staging, 'prefix', 'phabricator');
$tag = $prefix.'/diff/'.$id;
$this->writeOkay(
pht('PUSH STAGING'),
pht('Pushing changes to staging area...'));
$err = phutil_passthru(
'git push --no-verify -- %s %s:refs/tags/%s',
$staging_uri,
$commit,
$tag);
if ($err) {
$this->writeWarn(
pht('STAGING FAILED'),
pht('Unable to push changes to the staging area.'));
} else {
$this->writeOkay(
pht('STAGING PUSHED'),
pht(
'Pushed a copy of the changes to tag "%s" in the staging area.',
$tag));
}
}
}

View file

@ -1338,6 +1338,30 @@ abstract class ArcanistWorkflow extends Phobject {
fwrite(STDERR, $msg);
}
final protected function writeInfo($title, $message) {
$this->writeStatusMessage(
phutil_console_format(
"<bg:blue>** %s **</bg> %s\n",
$title,
$message));
}
final protected function writeWarn($title, $message) {
$this->writeStatusMessage(
phutil_console_format(
"<bg:yellow>** %s **</bg> %s\n",
$title,
$message));
}
final protected function writeOkay($title, $message) {
$this->writeStatusMessage(
phutil_console_format(
"<bg:green>** %s **</bg> %s\n",
$title,
$message));
}
final protected function isHistoryImmutable() {
$repository_api = $this->getRepositoryAPI();
@ -1669,6 +1693,11 @@ abstract class ArcanistWorkflow extends Phobject {
}
final protected function getRepositoryStagingConfiguration() {
return idx($this->getRepositoryInformation(), 'staging');
}
/**
* Get human-readable reasoning explaining how `arc` evaluated which
* Phabricator repository corresponds to this working copy. Used by