File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 22
33set -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+
517usage () {
618 cat << USAGE
719Usage:
@@ -38,9 +50,18 @@ require_cmds() {
3850}
3951
4052repo_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
Original file line number Diff line number Diff line change 22set -euo pipefail
33
44script_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
613usage () {
714 cat << USAGE
@@ -13,18 +20,18 @@ USAGE
1320}
1421
1522if [ " $# " -eq 1 ]; then
16- exec " $script_dir /pr " merge-verify " $1 "
23+ exec " $base " merge-verify " $1 "
1724fi
1825
1926if [ " $# " -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
Original file line number Diff line number Diff line change 88
99mode=" $1 "
1010pr=" $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
1320case " $mode " in
1421 init)
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22set -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 " $@ "
You can’t perform that action at this time.
0 commit comments