From 045d997ff07b0ea5e4f4eba6cd5fd91816e46853 Mon Sep 17 00:00:00 2001 From: spacewander Date: Wed, 5 Oct 2022 21:30:14 +0800 Subject: [PATCH] git root: show '.' when using with -r in the root dir Fix #993 Signed-off-by: spacewander --- bin/git-root | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/git-root b/bin/git-root index a308ce738..95a8a1181 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