From 584e0283f5baed2e86e831b2d16700ccfe0a659b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Thu, 6 Oct 2022 13:56:07 +0800 Subject: [PATCH] git root: show '.' when using with -r in the root dir (#995) --- bin/git-root | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/git-root b/bin/git-root index a308ce7..95a8a11 100755 --- a/bin/git-root +++ b/bin/git-root @@ -6,7 +6,13 @@ git_root() { # get the relative path of current path according to root of repo git_root_relative() { - git rev-parse --show-prefix + rel=$(git rev-parse --show-prefix) + if [ -z "$rel" ]; then + # git rev-parse --show-prefix will output empty string when we are in the root dir + echo "." + else + echo "$rel" + fi } if test $# -eq 0; then