diff --git a/skills/ingest/scripts/open-pr.sh b/skills/ingest/scripts/open-pr.sh index 3e979ff..0e6ff63 100755 --- a/skills/ingest/scripts/open-pr.sh +++ b/skills/ingest/scripts/open-pr.sh @@ -16,10 +16,11 @@ set -euo pipefail : "${FORGEJO_USER:?missing FORGEJO_USER}" : "${FORGEJO_TOKEN:?missing FORGEJO_TOKEN}" -slug="" title="" body_file="" base="main" label="" +slug="" title="" body_file="" base="main" label="" branch="" while [[ $# -gt 0 ]]; do case "$1" in --slug) slug="$2"; shift 2 ;; + --branch) branch="$2"; shift 2 ;; --title) title="$2"; shift 2 ;; --body-file) body_file="$2"; shift 2 ;; --base) base="$2"; shift 2 ;; @@ -28,16 +29,23 @@ while [[ $# -gt 0 ]]; do esac done -: "${slug:?--slug required}" : "${title:?--title required}" : "${body_file:?--body-file required}" [[ -f "$body_file" ]] || { echo "open-pr: body file not found: $body_file" >&2; exit 1; } -branch="feat/ai-ingest-${slug}" +# --branch overrides the default; otherwise derive the ingest branch from --slug. +# (run-prune passes its own chore/prune-orphans-* branch; run-ingest passes --slug.) +if [[ -z "$branch" ]]; then + : "${slug:?--slug or --branch required}" + branch="feat/ai-ingest-${slug}" +fi repo="$(basename -s .git "$(git config --get remote.origin.url)")" # 1. Branch + commit + push (AGENTS.md rule 5: never commit to main) -git switch -c "$branch" 2>/dev/null || git switch "$branch" +# Rolling PR: -C force-resets the branch label to the current base (we are on it after +# clean_start) and CARRIES the freshly-written wiki/ changes, so a re-ingest of the same +# source rebuilds the branch cleanly instead of hitting a dirty-switch refusal. +git switch -C "$branch" git add wiki/ # Scope BOTH the emptiness check and the commit to wiki/ — never commit anything that # happened to be staged outside wiki/ (a stray hook, an aborted prior run, etc.). @@ -46,7 +54,10 @@ if git diff --cached --quiet -- wiki/; then exit 1 fi git commit -m "$title" -- wiki/ -git push -u origin "$branch" +# Try a normal push (new branch / fast-forward). If the branch was rebuilt from base and +# diverged, force-with-lease updates the open PR in place — the lease refuses to clobber if +# origin moved unexpectedly since our fetch, so concurrent work is never lost. +git push -u origin "$branch" 2>/dev/null || git push -u --force-with-lease origin "$branch" # DRY_RUN: local git work done; skip the Forgejo API (offline tests). if [[ -n "${DRY_RUN:-}" ]]; then