Browse Source

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 <iannucci@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Leszek Swirski 6 years ago
parent
commit
33bd582224
1 changed files with 1 additions and 1 deletions
  1. 1 1
      git-nav-upstream

+ 1 - 1
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}"