From a77a77817a0399cb2c543f3a6aa03883cebf8837 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 20 Nov 2015 10:55:37 -0800 Subject: [PATCH] Try switching to the branch of the same name, instead of detached head Summary: Landing from a branch that directly tracks origin/master places one in a detached HEAD state. Instead, examine if there is a local branch of the name that we landed onto, that also tracks the upstream; if so, switch to that. Test Plan: Made a branch via `git checkout -b testing origin/master` and tried to `arc land` Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T9723 Differential Revision: https://secure.phabricator.com/D14420 --- src/land/ArcanistGitLandEngine.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/land/ArcanistGitLandEngine.php b/src/land/ArcanistGitLandEngine.php index 95b33aa1..7256b050 100644 --- a/src/land/ArcanistGitLandEngine.php +++ b/src/land/ArcanistGitLandEngine.php @@ -262,13 +262,26 @@ final class ArcanistGitLandEngine $path->removeUpstream($local_branch); if (!$path->getLength()) { - $this->writeInfo( - pht('UPDATE'), - pht( - 'Local branch "%s" directly tracks remote, staying on '. - 'detached HEAD.', - $local_branch)); - return; + // The local branch tracked upstream directly; however, it + // may not be the only one to do so. If there's a local + // branch of the same name that tracks the remote, try + // switching to that. + $local_branch = $this->getTargetOnto(); + list($err) = $api->execManualLocal( + 'rev-parse --verify %s', + $local_branch); + if (!$err) { + $path = $api->getPathToUpstream($local_branch); + } + if (!$path->isConnectedToRemote()) { + $this->writeInfo( + pht('UPDATE'), + pht( + 'Local branch "%s" directly tracks remote, staying on '. + 'detached HEAD.', + $local_branch)); + return; + } } $local_branch = head($path->getLocalBranches()); -- 2.43.0