From e0038c0721935fc3d8119e02c19553f2fee8f8fd Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 16 May 2024 17:44:14 +0000 Subject: [PATCH] print slightly better message if git nav-upstream is not called in git repo Currently, the command will print following message twice when not called in git repo. ``` fatal: not a git repository (or any parent up to mount point /google) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). ``` Bug: 339231299 Change-Id: Iab05e037a81b7e15dcc011d78480cd9ace7c7e36 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5544438 Commit-Queue: Yiwei Zhang Reviewed-by: Josip Sokcevic --- git-nav-upstream | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/git-nav-upstream b/git-nav-upstream index 6c7190b2c..ac48a4934 100755 --- a/git-nav-upstream +++ b/git-nav-upstream @@ -3,4 +3,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -git checkout "$(git rev-parse --abbrev-ref "@{u}")" +if git rev-parse 2> /dev/null; then + git checkout "$(git rev-parse --abbrev-ref "@{u}")" +else + echo "error: not in a git repository" >&2 + exit 1 +fi