From 685573508586eaf59c7d8f3aa88c2332c9f80007 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Sun, 23 Jul 2023 19:34:44 +0000 Subject: [PATCH] chore(scripts): support sappling in project_root --- scripts/lib.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/lib.sh b/scripts/lib.sh index f5cf7a97c0..bf83eeebd4 100644 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -41,7 +41,17 @@ realpath() { # We have to define realpath before these otherwise it fails on Mac's bash. SCRIPT="${BASH_SOURCE[1]:-${BASH_SOURCE[0]}}" SCRIPT_DIR="$(realpath "$(dirname "$SCRIPT")")" -PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(git rev-parse --show-toplevel)")" + +function project_root { + dir=$(pwd) + + while [[ "$dir" != "" && ! -e "$dir/.git" && ! -e "$dir/.sl" ]]; do + dir=${dir%/*} + done + + echo "$dir" +} +PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(project_root)")" # pushd is a silent alternative to the real pushd shell command. pushd() {