]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Push to staging areas when running "arc diff"
authorepriestley <git@epriestley.com>
Wed, 27 May 2015 17:27:03 +0000 (10:27 -0700)
committerepriestley <git@epriestley.com>
Wed, 27 May 2015 17:27:03 +0000 (10:27 -0700)
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

src/workflow/ArcanistDiffWorkflow.php
src/workflow/ArcanistWorkflow.php

index b77b41c4c1589b5c84a1b0e3b5f1a551a5c05f5f..808c73037fdd263bb21596ed0946a3b27390359c 100644 (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));
+    }
+  }
+
 }
index 3873e4f462386a29ee12cec65c1d29be84618a64..f24845d914c792370d3582a232ced44de8ea1de2 100644 (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