1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-02-16 16:58:38 +01:00

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
This commit is contained in:
Alex Vandiver 2015-11-20 10:55:37 -08:00
parent 2eada58960
commit a77a77817a

View file

@ -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());