From 33bd5822245c5b1ace318f3a5340a983889d07c7 Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Fri, 22 Mar 2019 01:10:26 +0000 Subject: [PATCH] Make git-nav-upstream include the current branch name Using just @{u} to navigate upstream breaks navigating back down when the upstream reaches a non-local branch, e.g. origin/master. This is because git branch walks the reflog for detached heads, and sees @{u} instead of e.g. origin/master, and so tries to calculate HEAD@{u} which fails. See also the message send to the git mailing list: https://public-inbox.org/git/CAGRskv__Qe-F-grBtq5v-uhHE+BQAcAcOQtX-GKB+MNOrxs0hQ@mail.gmail.com/ This patch works around this by manually specifying the branch from which we are calculating upstream, e.g. for branch foo we do git checkout foo@{u} instead of just git checkout @{u}. This ensures that the reflog has a valid entry (albeit still a relative one). Change-Id: I339d4e4288a1e104b9d7d3d568c45b2b156f0689 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1534217 Reviewed-by: Robbie Iannucci Commit-Queue: Robbie Iannucci Auto-Submit: Leszek Swirski --- git-nav-upstream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-nav-upstream b/git-nav-upstream index f16dc2ff46..e44e397571 100755 --- a/git-nav-upstream +++ b/git-nav-upstream @@ -3,4 +3,4 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -git checkout '@{u}' +git checkout "$(git rev-parse --abbrev-ref HEAD)@{u}"