mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
chore: fix root_dir resolution/stale scripts during PR review
This commit is contained in:
@@ -19,6 +19,7 @@ Merge a prepared PR only after deterministic validation.
|
||||
- Never use `gh pr merge --auto` in this flow.
|
||||
- Never run `git push` directly.
|
||||
- Require `--match-head-commit` during merge.
|
||||
- Wrapper commands are cwd-agnostic; you can run them from repo root or inside the PR worktree.
|
||||
|
||||
## Execution Contract
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ Perform a read-only review and produce both human and machine-readable outputs.
|
||||
|
||||
- Never push, merge, or modify code intended to keep.
|
||||
- Work only in `.worktrees/pr-<PR>`.
|
||||
- Wrapper commands are cwd-agnostic; you can run them from repo root or inside the PR worktree.
|
||||
|
||||
## Execution Contract
|
||||
|
||||
|
||||
23
scripts/pr
23
scripts/pr
@@ -2,6 +2,18 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# If invoked from a linked worktree copy of this script, re-exec the canonical
|
||||
# script from the repository root so behavior stays consistent across worktrees.
|
||||
script_self="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
|
||||
script_parent_dir="$(dirname "$script_self")"
|
||||
if common_git_dir=$(git -C "$script_parent_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
|
||||
canonical_repo_root="$(dirname "$common_git_dir")"
|
||||
canonical_self="$canonical_repo_root/scripts/$(basename "${BASH_SOURCE[0]}")"
|
||||
if [ "$script_self" != "$canonical_self" ] && [ -x "$canonical_self" ]; then
|
||||
exec "$canonical_self" "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
Usage:
|
||||
@@ -38,9 +50,18 @@ require_cmds() {
|
||||
}
|
||||
|
||||
repo_root() {
|
||||
# Resolve canonical root from script location so wrappers work from root or worktree cwd.
|
||||
# Resolve canonical repository root from git common-dir so wrappers work
|
||||
# the same from main checkout or any linked worktree.
|
||||
local script_dir
|
||||
local common_git_dir
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
|
||||
(cd "$(dirname "$common_git_dir")" && pwd)
|
||||
return
|
||||
fi
|
||||
|
||||
# Fallback for environments where git common-dir is unavailable.
|
||||
(cd "$script_dir/.." && pwd)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(cd "$(dirname "$0")" && pwd)"
|
||||
base="$script_dir/pr"
|
||||
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
|
||||
canonical_base="$(dirname "$common_git_dir")/scripts/pr"
|
||||
if [ -x "$canonical_base" ]; then
|
||||
base="$canonical_base"
|
||||
fi
|
||||
fi
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
@@ -13,7 +20,7 @@ USAGE
|
||||
}
|
||||
|
||||
if [ "$#" -eq 1 ]; then
|
||||
exec "$script_dir/pr" merge-verify "$1"
|
||||
exec "$base" merge-verify "$1"
|
||||
fi
|
||||
|
||||
if [ "$#" -eq 2 ]; then
|
||||
@@ -21,10 +28,10 @@ if [ "$#" -eq 2 ]; then
|
||||
pr="$2"
|
||||
case "$mode" in
|
||||
verify)
|
||||
exec "$script_dir/pr" merge-verify "$pr"
|
||||
exec "$base" merge-verify "$pr"
|
||||
;;
|
||||
run)
|
||||
exec "$script_dir/pr" merge-run "$pr"
|
||||
exec "$base" merge-run "$pr"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
|
||||
@@ -8,7 +8,14 @@ fi
|
||||
|
||||
mode="$1"
|
||||
pr="$2"
|
||||
base="$(cd "$(dirname "$0")" && pwd)/pr"
|
||||
script_dir="$(cd "$(dirname "$0")" && pwd)"
|
||||
base="$script_dir/pr"
|
||||
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
|
||||
canonical_base="$(dirname "$common_git_dir")/scripts/pr"
|
||||
if [ -x "$canonical_base" ]; then
|
||||
base="$canonical_base"
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$mode" in
|
||||
init)
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
exec "$(cd "$(dirname "$0")" && pwd)/pr" review-init "$@"
|
||||
|
||||
script_dir="$(cd "$(dirname "$0")" && pwd)"
|
||||
base="$script_dir/pr"
|
||||
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
|
||||
canonical_base="$(dirname "$common_git_dir")/scripts/pr"
|
||||
if [ -x "$canonical_base" ]; then
|
||||
base="$canonical_base"
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$base" review-init "$@"
|
||||
|
||||
Reference in New Issue
Block a user