compass

orient-files, orient-entrypoints: route project-root resolution through find-project-root

commit 9920325da14a84324f7f381a7d87692d018b4f25 · parent 2ab2c888ab · browse this tree
Ximianth, 2026-06-24 17:23:04 UTC

Both scripts previously inlined `git rev-parse --show-toplevel` for their
"resolve the search root" logic.  Now they delegate to find-project-root
and apply their own cwd fallback on top.

Behaviour is unchanged.  The point is SSOT: when the definition of
"current project" inevitably grows (additional marker conventions,
configurable overrides), it grows in one place.

`orient-git` deliberately keeps its direct git call: its job is to describe
the git context, so asking git directly is on-purpose, not duplication.
diff --git a/orient-entrypoints b/orient-entrypoints
index dc04775..f5a6626 100755
--- a/orient-entrypoints
+++ b/orient-entrypoints
@@ -21,10 +21,13 @@ set -euo pipefail
 
 HERE=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
 
-# Resolve the project root (mirrors orient-project).
+# Resolve the project root via the single source of truth.
+# `find-project-root` is strict (git toplevel or exit 1); we add a cwd
+# fallback here since this script still wants to detect entrypoints in
+# unmanaged directories.
 if [ $# -ge 1 ]; then
 	root=$(cd "$1" && pwd)
-elif root=$(git rev-parse --show-toplevel 2>/dev/null); then
+elif root=$("$HERE/find-project-root" 2>/dev/null); then
 	:
 else
 	root="$PWD"
diff --git a/orient-files b/orient-files
index 3321eba..cbe9405 100755
--- a/orient-files
+++ b/orient-files
@@ -67,10 +67,13 @@ while [ $# -gt 0 ]; do
 	esac
 done
 
-# Resolve the search root.
+# Resolve the search root via the single source of truth.
+# `find-project-root` is strict (git toplevel or exit 1); we add a cwd
+# fallback here since classifying files outside a project is still useful.
+self_dir=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)
 if [ $# -ge 1 ]; then
 	root=$(cd "$1" && pwd)
-elif root=$(git rev-parse --show-toplevel 2>/dev/null); then
+elif root=$("$self_dir/find-project-root" 2>/dev/null); then
 	:
 else
 	root="$PWD"