]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use GIT tracked branches for arc land targets when reasonable
authorJoseph Battelle <git@bttelle.com>
Mon, 28 Jul 2014 23:22:04 +0000 (16:22 -0700)
committerepriestley <git@epriestley.com>
Mon, 28 Jul 2014 23:22:09 +0000 (16:22 -0700)
Summary:
See T5690.
-arc land now respects tracked branch when choosing 'onto'; '--onto' option remains as an override.
-arc land now respects tracked branch when choosing a remote; the remote is taken from 'onto's upstream unless the '--remote' option is present; when 'onto' branch has no upstream the '--remote' option must be provided as before.

Since 'arc feature' branches are (already) created as tracking branches, 'arc.land.onto.default' if present, is only used as the default when a non-tracking branch created by some other means is landed with out explicit '--onto'.  This may be surprising but is probably the correct go-forward behavior and is inline with the description in T5690.

Test Plan:
-checked having no arc.land.onto.default still assumes 'master'
-checked 'arc.land.onto.default' still overrides 'master'
-checked upstream branch (of feature branch) overrides 'master' and 'arc.land.onto.default'
-checked '--onto' overrides all
-checked origin is default for non-tracking branches
-checked the land onto branch's upstream remote is used instead of 'origin'
-checked '--remote' overrides 'origin' and the tracked upstream
-tested several crazy branch names including 'something/like/this' for both the upstream and tracking branches
-tested on linux and OS X
-rinse and repeat on Windows

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T5690

Differential Revision: https://secure.phabricator.com/D10058

src/workflow/ArcanistLandWorkflow.php

index 1d9ebfb9fd58ce70e69740b1c11717473fab4592..f69edc27b1e5a6228cd145f5db03764d18c2f421 100644 (file)
@@ -218,6 +218,22 @@ EOTEXT
     return 0;
   }
 
+  private function getUpstreamMatching($branch, $pattern) {
+    if ($this->isGit) {
+      $repository_api = $this->getRepositoryAPI();
+      list($err, $fullname) = $repository_api->execManualLocal(
+        'rev-parse --symbolic-full-name %s@{upstream}',
+        $branch);
+      if (!$err) {
+        $matches = null;
+        if (preg_match($pattern, $fullname, $matches)) {
+          return last($matches);
+        }
+      }
+    }
+    return null;
+  }
+
   private function readArguments() {
     $repository_api = $this->getRepositoryAPI();
     $this->isGit = $repository_api instanceof ArcanistGitAPI;
@@ -275,10 +291,16 @@ EOTEXT
     $onto_default = nonempty(
       $this->getConfigFromAnySource('arc.land.onto.default'),
       $onto_default);
+    $onto_default = coalesce(
+      $this->getUpstreamMatching($this->branch, '/^refs\/heads\/(.+)$/'),
+      $onto_default);
     $this->onto = $this->getArgument('onto', $onto_default);
     $this->ontoType = $this->getBranchType($this->onto);
 
     $remote_default = $this->isGit ? 'origin' : '';
+    $remote_default = coalesce(
+      $this->getUpstreamMatching($this->onto, '/^refs\/remotes\/(.+?)\//'),
+      $remote_default);
     $this->remote = $this->getArgument('remote', $remote_default);
 
     if ($this->getArgument('merge')) {