From d56bf52141b7b66aa6b78b374057d432f8136231 Mon Sep 17 00:00:00 2001 From: Ammar Bandukwala Date: Sun, 23 Jul 2023 15:59:49 -0500 Subject: [PATCH] chore(scripts): support Sapling in project_root (#8685) --- scripts/lib.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/lib.sh b/scripts/lib.sh index f5cf7a97c0..1b4c48c784 100644 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -41,7 +41,19 @@ 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 { + # Try to use `git rev-parse --show-toplevel` to find the project root. + # If this directory is not a git repository, this command will fail. + git rev-parse --show-toplevel 2>/dev/null && return + + # This finds the Sapling root. This behavior is added so that @ammario + # and others can more easily experiment with Sapling, but we do not have a + # plan to support Sapling across the repo. + sl root 2>/dev/null && return +} + +PROJECT_ROOT="$(cd "$SCRIPT_DIR" && realpath "$(project_root)")" # pushd is a silent alternative to the real pushd shell command. pushd() {