Skip to content

Commit 42eaee8

Browse files
committed
chore: fix root_dir resolution/stale scripts during PR review
1 parent 6442512 commit 42eaee8

6 files changed

Lines changed: 53 additions & 6 deletions

File tree

‎.agents/skills/merge-pr/SKILL.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Merge a prepared PR only after deterministic validation.
1919
- Never use `gh pr merge --auto` in this flow.
2020
- Never run `git push` directly.
2121
- Require `--match-head-commit` during merge.
22+
- Wrapper commands are cwd-agnostic; you can run them from repo root or inside the PR worktree.
2223

2324
## Execution Contract
2425

‎.agents/skills/review-pr/SKILL.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Perform a read-only review and produce both human and machine-readable outputs.
1818

1919
- Never push, merge, or modify code intended to keep.
2020
- Work only in `.worktrees/pr-<PR>`.
21+
- Wrapper commands are cwd-agnostic; you can run them from repo root or inside the PR worktree.
2122

2223
## Execution Contract
2324

‎scripts/pr‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
set -euo pipefail
44

5+
# If invoked from a linked worktree copy of this script, re-exec the canonical
6+
# script from the repository root so behavior stays consistent across worktrees.
7+
script_self="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
8+
script_parent_dir="$(dirname "$script_self")"
9+
if common_git_dir=$(git -C "$script_parent_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
10+
canonical_repo_root="$(dirname "$common_git_dir")"
11+
canonical_self="$canonical_repo_root/scripts/$(basename "${BASH_SOURCE[0]}")"
12+
if [ "$script_self" != "$canonical_self" ] && [ -x "$canonical_self" ]; then
13+
exec "$canonical_self" "$@"
14+
fi
15+
fi
16+
517
usage() {
618
cat <<USAGE
719
Usage:
@@ -38,9 +50,18 @@ require_cmds() {
3850
}
3951

4052
repo_root() {
41-
# Resolve canonical root from script location so wrappers work from root or worktree cwd.
53+
# Resolve canonical repository root from git common-dir so wrappers work
54+
# the same from main checkout or any linked worktree.
4255
local script_dir
56+
local common_git_dir
4357
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
58+
59+
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
60+
(cd "$(dirname "$common_git_dir")" && pwd)
61+
return
62+
fi
63+
64+
# Fallback for environments where git common-dir is unavailable.
4465
(cd "$script_dir/.." && pwd)
4566
}
4667

‎scripts/pr-merge‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
set -euo pipefail
33

44
script_dir="$(cd "$(dirname "$0")" && pwd)"
5+
base="$script_dir/pr"
6+
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
7+
canonical_base="$(dirname "$common_git_dir")/scripts/pr"
8+
if [ -x "$canonical_base" ]; then
9+
base="$canonical_base"
10+
fi
11+
fi
512

613
usage() {
714
cat <<USAGE
@@ -13,18 +20,18 @@ USAGE
1320
}
1421

1522
if [ "$#" -eq 1 ]; then
16-
exec "$script_dir/pr" merge-verify "$1"
23+
exec "$base" merge-verify "$1"
1724
fi
1825

1926
if [ "$#" -eq 2 ]; then
2027
mode="$1"
2128
pr="$2"
2229
case "$mode" in
2330
verify)
24-
exec "$script_dir/pr" merge-verify "$pr"
31+
exec "$base" merge-verify "$pr"
2532
;;
2633
run)
27-
exec "$script_dir/pr" merge-run "$pr"
34+
exec "$base" merge-run "$pr"
2835
;;
2936
*)
3037
usage

‎scripts/pr-prepare‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ fi
88

99
mode="$1"
1010
pr="$2"
11-
base="$(cd "$(dirname "$0")" && pwd)/pr"
11+
script_dir="$(cd "$(dirname "$0")" && pwd)"
12+
base="$script_dir/pr"
13+
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
14+
canonical_base="$(dirname "$common_git_dir")/scripts/pr"
15+
if [ -x "$canonical_base" ]; then
16+
base="$canonical_base"
17+
fi
18+
fi
1219

1320
case "$mode" in
1421
init)

‎scripts/pr-review‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
exec "$(cd "$(dirname "$0")" && pwd)/pr" review-init "$@"
3+
4+
script_dir="$(cd "$(dirname "$0")" && pwd)"
5+
base="$script_dir/pr"
6+
if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
7+
canonical_base="$(dirname "$common_git_dir")/scripts/pr"
8+
if [ -x "$canonical_base" ]; then
9+
base="$canonical_base"
10+
fi
11+
fi
12+
13+
exec "$base" review-init "$@"

0 commit comments

Comments
 (0)