diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 68f26c4..792707f 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -474,31 +474,31 @@ set -e # REPO is injected at install time; try to resolve canonical project root using # git when available to avoid mistakenly selecting parent directories. +# Try to locate the repo root dynamically. Use the embedded __REPO__ value as a hint, +# but prefer to discover a repo from the current working directory or git. REPO="__REPO__" -if command -v git >/dev/null 2>&1; then - gitroot=$(git -C "$REPO" rev-parse --show-toplevel 2>/dev/null || true) - if [ -n "$gitroot" ]; then - REPO="$gitroot" - else - # Try resolving from the current working directory +# If the placeholder does not appear to point at a repo, attempt discovery. +if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then + # First try to find a git toplevel from the current working directory. + if command -v git >/dev/null 2>&1; then gitroot=$(git -C "$(pwd -P)" rev-parse --show-toplevel 2>/dev/null || true) if [ -n "$gitroot" ]; then REPO="$gitroot" fi fi -else - # Fallback: walk up from CWD to find CLI.py or pyproject.toml - if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then - CUR="$(pwd -P)" - while [ "$CUR" != "/" ] && [ "$CUR" != "" ]; do - if [ -f "$CUR/CLI.py" ] || [ -f "$CUR/pyproject.toml" ]; then - REPO="$CUR" - break - fi - CUR="$(dirname "$CUR")" - done - fi fi +# If still unresolved, walk up from the CWD looking for signs of the project. +if [ ! -f "$REPO/CLI.py" ] && [ ! -f "$REPO/pyproject.toml" ]; then + CUR="$(pwd -P)" + while [ "$CUR" != "/" ] && [ "$CUR" != "" ]; do + if [ -f "$CUR/CLI.py" ] || [ -f "$CUR/pyproject.toml" ]; then + REPO="$CUR" + break + fi + CUR="$(dirname "$CUR")" + done +fi +# At this point REPO may still be wrong if mm was invoked outside any project; keep the embedded path as a last resort. VENV="$REPO/.venv" @@ -565,10 +565,30 @@ exit 127 MM # Inject absolute repo path into the installed script so global launcher prefers the project venv -escaped_repo=$(printf '%s' "$REPO" | sed -e 's/[\/&]/\\&/g') -sed -i "s|__REPO__|$escaped_repo|g" "$USER_BIN/mm" || true +# Replace __REPO__ placeholder robustly using Python (preferred) else fallback to sed +if command -v python >/dev/null 2>&1; then + python - <&2 +fi + # Quick verification of the global launcher; helps catch packaging issues early. if "$USER_BIN/mm" --help >/dev/null 2>&1; then echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly."