Page MenuHomePhabricator

D10058.id24184.diff
No OneTemporary

D10058.id24184.diff

diff --git a/src/workflow/ArcanistLandWorkflow.php b/src/workflow/ArcanistLandWorkflow.php
--- a/src/workflow/ArcanistLandWorkflow.php
+++ b/src/workflow/ArcanistLandWorkflow.php
@@ -218,6 +218,50 @@
return 0;
}
+ private function getTrackingBranchDescriptor($branch) {
+ // NOTE: tracking branches are identified by comparing -v and -vv outputs
+ // of branch --list. git help for the -v option declares:
+ // "...If given twice, print the name of the upstream branch, as well"
+ // This correctly handles the case where git commit history contains
+ // [..something that looks like a branch..] in the commit summary line.
+ if ($this->isGit) {
+ $repository_api = $this->getRepositoryAPI();
+ list($branch_v) = $repository_api->execxLocal(
+ 'branch --list -v --no-color %s',
+ $branch);
+ list($branch_vv) = $repository_api->execxLocal(
+ 'branch --list -vv --no-color %s',
+ $branch);
+ if ($branch_vv != $branch_v) {
+ return $branch_vv;
+ }
+ }
+ return null;
+ }
+
+ private function getTrackedLocalBranchName() {
+ $tracking = $this->getTrackingBranchDescriptor($this->branch);
+ if ($tracking) {
+ // match local tracked branches only
+ $matches = null;
+ if (preg_match('/\[(\w+)[^\/]/', $tracking, $matches)) {
+ return last($matches);
+ }
+ }
+ return null;
+ }
+
+ private function getTrackedRemoteName() {
+ $tracking = $this->getTrackingBranchDescriptor($this->onto);
+ if ($tracking) {
+ $matches = null;
+ if (preg_match('/\[(\w+)\/(\w+)/', $tracking, $matches)) {
+ return $matches[1];
+ }
+ }
+ return null;
+ }
+
private function readArguments() {
$repository_api = $this->getRepositoryAPI();
$this->isGit = $repository_api instanceof ArcanistGitAPI;
@@ -275,10 +319,12 @@
$onto_default = nonempty(
$this->getConfigFromAnySource('arc.land.onto.default'),
$onto_default);
+ $onto_default = coalesce($this->getTrackedLocalBranchName(), $onto_default);
$this->onto = $this->getArgument('onto', $onto_default);
$this->ontoType = $this->getBranchType($this->onto);
$remote_default = $this->isGit ? 'origin' : '';
+ $remote_default = coalesce($this->getTrackedRemoteName(), $remote_default);
$this->remote = $this->getArgument('remote', $remote_default);
if ($this->getArgument('merge')) {

File Metadata

Mime Type
text/plain
Expires
May 14 2024, 5:11 PM (4 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6295490
Default Alt Text
D10058.id24184.diff (2 KB)

Event Timeline