From: Joseph Battelle Date: Mon, 28 Jul 2014 23:22:04 +0000 (-0700) Subject: Use GIT tracked branches for arc land targets when reasonable X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bb6d11b732228bf82adf4f9cbafb0555843c0faa;p=arcanist.git Use GIT tracked branches for arc land targets when reasonable 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 --- diff --git a/src/workflow/ArcanistLandWorkflow.php b/src/workflow/ArcanistLandWorkflow.php index 1d9ebfb9..f69edc27 100644 --- a/src/workflow/ArcanistLandWorkflow.php +++ b/src/workflow/ArcanistLandWorkflow.php @@ -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')) {