Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Push to staging areas when running "arc diff"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epriestley committed May 27, 2015
1 parent a36dc81 commit 3ac8020
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/workflow/ArcanistDiffWorkflow.php
Expand Up @@ -370,6 +370,9 @@ public function getArguments() {
'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.'),
),
Expand Down Expand Up @@ -517,6 +520,8 @@ public function run() {
'unitResult' => $unit_result,
));

$this->pushChangesToStagingArea($this->diffID);

$this->updateLintDiffProperty();
$this->updateUnitDiffProperty();
$this->updateLocalDiffProperty();
Expand Down Expand Up @@ -2604,4 +2609,85 @@ private function shouldOpenCreatedObjectsInBrowser() {
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));
}
}

}
29 changes: 29 additions & 0 deletions src/workflow/ArcanistWorkflow.php
Expand Up @@ -1338,6 +1338,30 @@ final protected function writeStatusMessage($msg) {
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();

Expand Down Expand Up @@ -1669,6 +1693,11 @@ final protected function getRepositoryURI() {
}


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
Expand Down

0 comments on commit 3ac8020

Please sign in to comment.