mirror of
https://github.com/obra/superpowers.git
synced 2026-08-31 19:09:13 +00:00
fix(sdd): reject empty or non-descendant BASE..HEAD ranges in review-package
When an SDD implementer commits to the wrong branch (#2050), the BASE..HEAD range handed to review-package is either empty or not rooted at BASE. Both cases previously produced a review package silently — an empty one lets the reviewer approve "clean" work that isn't there. Add two mechanical guards after BASE/HEAD validation, exiting 3 (vs 2 for usage errors) so callers can distinguish range problems: - git merge-base --is-ancestor BASE HEAD, else "HEAD is not a descendant of BASE" - git rev-list --count BASE..HEAD > 0, else "empty commit range" Guard shape credits the analysis in closed PR #2082 by @stantheman0128. Fixes #2050
This commit is contained in:
@@ -165,6 +165,30 @@ PLAN
|
||||
echo " got: $rp_explicit"
|
||||
fi
|
||||
|
||||
# --- range guards: BASE must be an ancestor of HEAD, range must be non-empty ---
|
||||
local divergent
|
||||
divergent="$(cd "$repo" && git "${git_id[@]}" commit-tree 'HEAD~1^{tree}' -p 'HEAD~1' -m divergent)"
|
||||
rc=0
|
||||
local guard_err
|
||||
guard_err="$(cd "$repo" && "$SDD_SCRIPTS/review-package" plan-a.md "$divergent" HEAD 2>&1 >/dev/null)" || rc=$?
|
||||
if [[ "$rc" -eq 3 && "$guard_err" == *"not a descendant"* ]]; then
|
||||
pass "review-package rejects a BASE that is not an ancestor of HEAD with exit 3"
|
||||
else
|
||||
fail "review-package rejects a BASE that is not an ancestor of HEAD with exit 3"
|
||||
echo " exit: $rc"
|
||||
echo " stderr: $guard_err"
|
||||
fi
|
||||
|
||||
rc=0
|
||||
guard_err="$(cd "$repo" && "$SDD_SCRIPTS/review-package" plan-a.md HEAD HEAD 2>&1 >/dev/null)" || rc=$?
|
||||
if [[ "$rc" -eq 3 && "$guard_err" == *"empty commit range"* ]]; then
|
||||
pass "review-package rejects an empty BASE..HEAD range with exit 3"
|
||||
else
|
||||
fail "review-package rejects an empty BASE..HEAD range with exit 3"
|
||||
echo " exit: $rc"
|
||||
echo " stderr: $guard_err"
|
||||
fi
|
||||
|
||||
# --- Worktree isolation: a linked worktree resolves its own workspace ---
|
||||
local wt="$TEST_ROOT/wt"
|
||||
( cd "$repo" && git worktree add -q "$wt" -b wt-feature )
|
||||
|
||||
Reference in New Issue
Block a user