fix(scripts): use one whole-history first landing for release tags

Why: the untagged-run branch looked for an earlier run of a version only
from the start of the wanted range, while tag validation used the first
landing across all history. After a backfill, a revert to a pre-backfill
version was tagged on the revert commit, and the next dry run reported
that tag as a later landing: exit 2, blocking --apply for every plugin.

Implementation Notes:
- first_run() returns the first valid run of a version over the whole
  first-parent history; tag validation, the tagged-elsewhere check, the
  backfill start and the untagged-run check all use it.
- An untagged version whose first landing lies before the wanted range
  reports RELEASED with a "before the tagged range; not tagged" note; no
  tag is created and the exit code is unaffected.
- Preflight rejects a plugin name whose tag git check-ref-format refuses
  (e.g. a..b, a*) before any history is read, so a glob character never
  reaches a pathspec or ref pattern; tags are listed once and filtered by
  exact prefix instead of a for-each-ref glob.
- git rev-list failure and an empty run list now exit 2 with a FAIL
  message instead of being read as no history or crashing.
- The error footer addresses agents (stop and report, AGENTS.md) and the
  maintainer (fix by hand, ADR-0033) separately.

Impact: ADR-0033 defines first landing precisely, documents the preflight,
and documents the maintainer escape from an INVALID run (hand-cut tag on
the next valid version; --apply stays all-or-nothing). New tests cover the
revert repro, a backfill range holding a pre-range version, the INVALID
escape, rev-list failure/empty history, a glob plugin name, and the footer.

Refs: #223
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-11-27 19:25:16 +00:00
1 parent 0a52c8597d
commit 62650543ec
3 files changed
+219 -52

No files matched your search

@@ -32,7 +32,9 @@ Two facts limit where enforcement can live:
- **Name.** `<plugin>` is the directory under `plugins/` and must equal that `apm.yml`'s `name`.
`<version>` is the strict `MAJOR.MINOR.PATCH` from the same file. Example: `git-v1.3.9`. The
repo-level `v*` tags stay as they are.
repo-level `v*` tags stay as they are. A plugin directory whose name starts with `-`, or whose
`<plugin>-v<version>` `git check-ref-format` rejects (`a..b`, `a*`), can never be tagged, so the
script rejects it before reading any history.
- **Target.** The tag goes on the oldest commit, in `main`'s first-parent history, of the
contiguous run carrying that version. That is the merge or squash commit where the version first
landed on `main`, never a feature-branch commit. An `apm.yml` edit that leaves `version:` alone
@@ -42,11 +44,19 @@ Two facts limit where enforcement can live:
first is reported as an error for a human to resolve. Every
reachable `<plugin>-v*` tag is checked this way, not only those of the wanted runs, and an
invalid one never decides where the wanted runs start, so it cannot hide the versions before it.
- **A version is released once, at its first landing.** When a version comes back (a reverted
bump, or an `apm.yml` deleted and re-added), the later run is not tagged again: its tag already
exists on the earlier run, so the script reports that run `RELEASED` and it blocks nothing. An
untagged version that recurs within the wanted runs is tagged at its first landing there, and
the later runs report `RELEASED`.
- **A version is released once, at its first landing.** A version's first landing is the oldest
run carrying it anywhere in `main`'s first-parent history, not only among the wanted runs. The
script uses this one definition both to validate existing tags and to decide which tags to
create. When a version comes back (a reverted bump, or an `apm.yml` deleted and re-added), the
later run is never tagged: the script reports it `RELEASED`, and it blocks nothing. There are
three cases:
- The version's tag exists: it must be on the first landing.
- The version is untagged and its first landing is among the wanted runs: that run is the one
tagged (`MISSING` until then).
- The version is untagged and its first landing lies before the wanted runs: the version shipped
before the tagging start point. It stays untagged, like the rest of the history the backfill
leaves out, and the later run reports `RELEASED` with a note naming the first landing. Tagging
the later run instead would cut a tag the next run reports as an error.
- **Mechanism.** `scripts/tag-plugin-releases.sh` computes the targets from `origin/main`'s
history and cuts the tags after merge. Without arguments it is a dry run: it prints a
`plugin version commit status` table and exits 1 if any tag is missing. `--apply` creates the
@@ -62,6 +72,15 @@ Two facts limit where enforcement can live:
first landing anywhere in history and any later run of it reports `RELEASED`; when the current
version never recurred, that is the current run alone. That second rule is the backfill: older
history is not tagged retroactively.
- **An invalid version blocks `--apply` until a maintainer resolves it.** A run in the wanted range
whose `version:` is not strict `MAJOR.MINOR.PATCH` is an error row, and because `--apply` is all
or nothing it blocks every plugin's tags, not only that plugin's. The script does not skip it,
since silently skipping a run would hide whatever version shipped there. The escape path belongs
to the maintainer: cut by hand the annotated tag of the first valid version after the invalid
run, on that version's first landing. That tag becomes the plugin's start point, the invalid
run is no longer wanted, and the next `--apply` proceeds. Any version between the old start
point and the invalid run is then the maintainer's to tag by hand too, if it is wanted at all.
An agent that hits this stops and reports, like any other exit 2.
- **One deliberate exception to the backfill: git's previous version, `git-v1.3.8`, is also
tagged**, on `32fbe39fb8923854ca8e743a0d2cad81720c736c`, where 1.3.8 first landed on `main`. This
gives a consumer pinned to an older git tag something real to check `apm outdated` against. It is
+89 -46
View File
@@ -47,18 +47,29 @@ set -euo pipefail
# no valid tag (the backfill), every run from the FIRST landing of the
# current version onward; when the current version never recurred, that is
# the current run alone. Older history is not tagged retroactively.
# - A version is released once, at its FIRST landing. When a version recurs
# (a revert, or apm.yml deleted and re-added), the later run is not tagged
# again: it reports RELEASED.
# - A version is released once, at its FIRST landing: the oldest valid run
# of that version anywhere in the ref's first-parent history. Validating
# existing tags and choosing what to create use this one definition. When
# a version recurs (a revert, or apm.yml deleted and re-added), the later
# run is never tagged: it reports RELEASED. If the version is untagged and
# its first landing lies before the wanted runs, it shipped before the
# tagging start point: the later run still reports RELEASED (with a note
# naming the first landing) and no tag is created for it.
# - Status per wanted run: MISSING (no tag), OK (annotated, peels to the
# target), RELEASED (the tag peels to an earlier run of the same version,
# or the version is untagged and an earlier wanted run carries it, so that
# run is the one tagged), ERROR (lightweight, peels to no landing of that
# version or to a later landing than its first, invalid version in
# history, or a tag name git rejects).
# - A plugin directory whose name starts with `-` is rejected (exit 2): its
# tag name would parse as an option.
# target), RELEASED (a later run of a version whose first landing is
# earlier, tagged or not), ERROR (lightweight, peels to anything but the
# version's first landing, or an invalid version in the wanted runs).
# RELEASED never blocks other rows and never changes the exit code.
# - An INVALID run inside the wanted runs is an ERROR, so --apply creates
# nothing for any plugin until it is resolved. The way out is the
# maintainer's (ADR-0033): cut by hand the annotated tag of the first valid
# version after the invalid run, on that version's first landing; it
# becomes the start point and the invalid run is no longer wanted.
#
# Preflight (exit 2 before any history is read): a selected plugin directory
# whose name starts with `-` (its tag would parse as an option) or whose
# `<p>-v<version>` git check-ref-format rejects (e.g. `a..b`, `a*`): no such
# tag can ever exist, so the plugin can never be released under this scheme.
#
# Tag matching is anchored: `<p>-v` followed by a strict semver and nothing
# else, so git, gitea and gitops never claim each other's tags.
@@ -195,14 +206,34 @@ if [[ ${#PLUGINS[@]} -eq 0 ]]; then
exit 2
fi
# A leading dash would make the tag name `-x-v1.0.0` parse as an option.
# A leading dash would make the tag name `-x-v1.0.0` parse as an option. A
# name git rejects as a ref (`..`, `*`, `[`, `?`, `\`, ...) can never be
# tagged. Both are rejected before any history is read, so such a name never
# reaches a pathspec or a ref pattern. The version part is strict semver
# (digits and single dots), so the name alone decides validity.
for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
if [[ "$p" == -* ]]; then
echo "ERROR: plugins/$p: a plugin name must not start with '-' (its tag would parse as an option)." >&2
exit 2
fi
if ! git check-ref-format "refs/tags/$p-v0.0.0"; then
echo "ERROR: plugins/$p: '$p-v<version>' is not a valid tag name (git check-ref-format); rename the plugin directory." >&2
exit 2
fi
done
# Every tag, listed once. A plugin's tags are picked out below by an exact
# string prefix in the shell, never by a for-each-ref pattern, so nothing in a
# plugin name is ever read as a glob.
if ! tag_list="$(git for-each-ref --format='%(refname:strip=2)' refs/tags/)"; then
echo "FAIL: git for-each-ref could not list tags." >&2
exit 2
fi
ALL_TAGS=()
if [[ -n "$tag_list" ]]; then
while IFS= read -r t; do ALL_TAGS+=("$t"); done <<< "$tag_list"
fi
# Reads "<commit>" lines on stdin and, for plugin path $1, prints one line per
# commit: "<commit> OK <name> <version>", "<commit> INVALID <name|-> -" when
# the version is not strict semver or the YAML does not parse, or
@@ -254,13 +285,16 @@ add_row() {
ROW_PLUGIN+=("$1"); ROW_VERSION+=("$2"); ROW_COMMIT+=("$3"); ROW_STATUS+=("$4"); ROW_DETAIL+=("$5")
}
# first_landing <version> <run index>: over the current plugin's runs, print
# the target of the first valid run of <version> before <run index> and
# succeed, or fail when that run is itself the version's first landing.
first_landing() {
# first_run <version> <run index>: over ALL the current plugin's runs (the
# whole first-parent history, not only the wanted ones), print the index of the
# first valid run of <version> before <run index> and succeed, or fail when
# there is none (that run is itself the version's first landing). Every "where
# did this version first land" question, whether validating a tag or deciding
# what to create, goes through this one function.
first_run() {
local j
for ((j = 0; j < $2; j++)); do
if [[ "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$1" ]]; then echo "${RUN_TARGET[j]}"; return 0; fi
if [[ "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$1" ]]; then echo "$j"; return 0; fi
done
return 1
}
@@ -273,9 +307,15 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
# Oldest first. --first-parent with a path keeps each first-parent commit
# whose apm.yml differs from its first parent's: on main that is the merge
# or squash commit that brought the change in.
# Captured first, so a git failure is caught rather than read as no history.
if ! revs="$(git rev-list --first-parent --reverse "$REF_COMMIT" -- "$apm_spec")"; then
echo "FAIL: git rev-list could not read $apm history at $REF (see error above)." >&2
exit 2
fi
COMMITS=()
while IFS= read -r c; do COMMITS+=("$c"); done \
< <(git rev-list --first-parent --reverse "$REF_COMMIT" -- "$apm_spec")
if [[ -n "$revs" ]]; then
while IFS= read -r c; do COMMITS+=("$c"); done <<< "$revs"
fi
LINES=()
while IFS= read -r l; do LINES+=("$l"); done \
@@ -317,6 +357,12 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
fi
done
nruns=${#RUN_VER[@]}
# apm.yml exists at the ref, so its history has at least one run; none means
# the history read is wrong, and every rule below would be meaningless.
if [[ $nruns -eq 0 ]]; then
echo "FAIL: $apm exists at $REF but no commit on its first-parent history carries it; cannot compute release targets." >&2
exit 2
fi
# Start point: the newest run a VALID reachable <p>-v<semver> tag peels to.
# Every such tag is validated first: annotated, and peeling to the target of
@@ -325,7 +371,7 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
# serves as the start point, so it cannot hide the runs before it.
anchor=-1
BAD_TAG=(); BAD_VER=(); BAD_COMMIT=(); BAD_DETAIL=()
while IFS= read -r tagname; do
for tagname in ${ALL_TAGS[@]+"${ALL_TAGS[@]}"}; do
[[ "$tagname" == "$p-v"* ]] || continue
tv="${tagname#"$p-v"}"
[[ "$tv" =~ $SEMVER_RE ]] || continue
@@ -349,13 +395,14 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
BAD_DETAIL+=("$tagname peels to ${peeled:0:7}, which is no landing of $tv on the first-parent history")
continue
fi
if fl="$(first_landing "$tv" "$pos")"; then
if fj="$(first_run "$tv" "$pos")"; then
fl="${RUN_TARGET[fj]}"
BAD_TAG+=("$tagname"); BAD_VER+=("$tv"); BAD_COMMIT+=("$peeled")
BAD_DETAIL+=("$tagname peels to ${peeled:0:7}, a later landing of $tv; it first landed at ${fl:0:7}")
continue
fi
[[ $pos -gt $anchor ]] && anchor=$pos
done < <(git for-each-ref --format='%(refname:strip=2)' "refs/tags/$p-v*")
done
if [[ $anchor -ge 0 ]]; then
first=$anchor
@@ -364,9 +411,7 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
# released once, there; a later run of it then reports RELEASED.
cur_ver="${RUN_VER[nruns - 1]}"
first=$((nruns - 1))
for ((i = 0; i < nruns; i++)); do
if [[ "${RUN_VALID[i]}" == true && "${RUN_VER[i]}" == "$cur_ver" ]]; then first=$i; break; fi
done
if fj="$(first_run "$cur_ver" "$nruns")"; then first=$fj; fi
fi
# Tags the run loop below reports itself, so the bad-tag rows skip them.
@@ -380,18 +425,18 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
fi
tag="$p-v$v"
if ! git rev-parse --verify -q "refs/tags/$tag" > /dev/null; then
# Untagged: the version is released at its first landing in the wanted
# set, so a later run of the same version is not tagged again.
earlier=""
for ((j = first; j < i; j++)); do
if [[ "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$v" ]]; then earlier="${RUN_TARGET[j]}"; break; fi
done
if [[ -n "$earlier" ]]; then
add_row "$p" "$v" "$target" RELEASED "$v is released at its first landing ${earlier:0:7}"
continue
fi
if ! git check-ref-format "refs/tags/$tag"; then
add_row "$p" "$v" "$target" ERROR "'$tag' is not a valid tag name (git check-ref-format)"
# Untagged. Only the version's first landing anywhere in history is
# ever tagged. Inside the wanted runs, that run is MISSING and this later
# one is RELEASED. Before them, the version shipped before the tagging
# start point: it stays untagged like the rest of that history, and
# tagging this later run would only be reported as a later landing.
if fj="$(first_run "$v" "$i")"; then
fl="${RUN_TARGET[fj]}"
if [[ $fj -lt $first ]]; then
add_row "$p" "$v" "$target" RELEASED "$v first landed at ${fl:0:7}, before the tagged range; not tagged"
else
add_row "$p" "$v" "$target" RELEASED "$v is released at its first landing ${fl:0:7}"
fi
continue
fi
add_row "$p" "$v" "$target" MISSING ""
@@ -404,7 +449,8 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
fi
peeled="$(git rev-parse --verify -q "refs/tags/$tag^{commit}" || true)"
if [[ "$peeled" == "$target" ]]; then
if fl="$(first_landing "$v" "$i")"; then
if fj="$(first_run "$v" "$i")"; then
fl="${RUN_TARGET[fj]}"
add_row "$p" "$v" "$target" ERROR "$tag peels to ${target:0:7}, a later landing of $v; it first landed at ${fl:0:7}"
REPORTED+=("$tag")
continue
@@ -412,17 +458,13 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
add_row "$p" "$v" "$target" OK ""
continue
fi
# Tagged elsewhere: fine only if it peels to an EARLIER run of the same
# version (the first landing, e.g. before a revert brought $v back).
landing=-1
for ((j = 0; j < i; j++)); do
if [[ "${RUN_TARGET[j]}" == "$peeled" && "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$v" ]]; then landing=$j; fi
done
if [[ $landing -ge 0 ]]; then
# Tagged elsewhere: fine only if it peels to the version's FIRST landing
# (e.g. before a revert brought $v back).
if fj="$(first_run "$v" "$i")" && [[ "${RUN_TARGET[fj]}" == "$peeled" ]]; then
add_row "$p" "$v" "$target" RELEASED "$tag already released at ${peeled:0:7}"
continue
fi
add_row "$p" "$v" "$target" ERROR "$tag peels to ${peeled:0:7}, not ${target:0:7} or any earlier landing of $v"
add_row "$p" "$v" "$target" ERROR "$tag peels to ${peeled:0:7}, which is not the first landing of $v"
REPORTED+=("$tag")
done
@@ -465,7 +507,8 @@ report_errors() {
for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do
[[ "${ROW_STATUS[i]}" == ERROR ]] && echo "ERROR: ${ROW_PLUGIN[i]}: ${ROW_DETAIL[i]}" >&2
done
echo "Tags are immutable: fix by hand only after deciding which commit each version belongs to (ADR-0033)." >&2
echo "Agents: stop and report this to the maintainer; never hand-fix, move or delete a tag (AGENTS.md)." >&2
echo "Maintainer: tags are immutable; fix by hand only after deciding which commit each version belongs to (ADR-0033)." >&2
}
if ! $APPLY; then
+105
View File
@@ -135,6 +135,8 @@ run "$R" --ref main
expect_rc "lightweight tag" 2
expect_row "row is ERROR" delta 2.0.0 "$BUMP" ERROR
if grep -q "lightweight" <<< "$OUT"; then pass "message names lightweight"; else fail "no lightweight message"; fi
if grep -q "^Agents: stop and report this to the maintainer" <<< "$OUT"; then pass "footer tells agents to stop and report"; else fail "no agent footer"; fi
if grep -q "^Maintainer: tags are immutable" <<< "$OUT"; then pass "footer addresses the maintainer"; else fail "no maintainer footer"; fi
echo "Case 5: annotated tag on the wrong commit is an ERROR"
(cd "$R" && git tag -d delta-v2.0.0 > /dev/null && git tag -a delta-v2.0.0 -m x "$EDIT")
@@ -478,6 +480,109 @@ expect_rc "--plugin git --plugin git --apply" 0
if [[ "$(git -C "$R" tag -l)" == "git-v1.0.0" ]]; then pass "one tag created"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
if grep -qx "git push origin git-v1.0.0" <<< "$OUT"; then pass "push line names the tag once"; else fail "push line wrong"; echo "$OUT" | sed 's/^/ /'; fi
echo "Case 12t: a revert to a version from before the tagged range is RELEASED, never tagged"
R="$(new_repo)"
write_apm "$R" rv 1.0.0; commit "$R" a; RV1="$(head_sha "$R")"
write_apm "$R" rv 1.1.0; commit "$R" b; RV2="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "backfill --apply tags the current version only" 0
if [[ "$(git -C "$R" tag -l)" == "rv-v1.1.0" ]]; then pass "only rv-v1.1.0 backfilled"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
write_apm "$R" rv 1.0.0; commit "$R" revert; RV3="$(head_sha "$R")"
write_apm "$R" rv 1.2.0; commit "$R" c; RV4="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref main
expect_rc "dry run: only the new bump is missing" 1
expect_row "backfilled 1.1.0 OK" rv 1.1.0 "$RV2" OK
expect_row "revert to pre-backfill 1.0.0 is RELEASED" rv 1.0.0 "$RV3" RELEASED
expect_row "new bump 1.2.0 MISSING" rv 1.2.0 "$RV4" MISSING
if grep -q "first landed at ${RV1:0:7}, before the tagged range; not tagged" <<< "$OUT"; then pass "note names the pre-range first landing"; else fail "no pre-range note"; echo "$OUT" | sed 's/^/ /'; fi
run "$R" --ref main --apply
expect_rc "--apply after the revert" 0
if [[ "$(git -C "$R" tag -l | tr '\n' ' ')" == "rv-v1.1.0 rv-v1.2.0 " ]]; then pass "rv-v1.2.0 created, no rv-v1.0.0"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
run "$R" --ref main
expect_rc "dry run after --apply is clean, never 2" 0
echo "Case 12t2: backfill whose range holds a version that first landed before it"
R="$(new_repo)"
write_apm "$R" rw 1.0.0; commit "$R" a; RW1="$(head_sha "$R")"
write_apm "$R" rw 1.1.0; commit "$R" b; RW2="$(head_sha "$R")"
write_apm "$R" rw 1.0.0; commit "$R" c; RW3="$(head_sha "$R")"
write_apm "$R" rw 1.1.0; commit "$R" d; RW4="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref main
expect_rc "backfill dry run" 1
expect_row "current version MISSING at its first landing" rw 1.1.0 "$RW2" MISSING
expect_row "1.0.0 inside the range is RELEASED" rw 1.0.0 "$RW3" RELEASED
expect_row "current version's later run RELEASED" rw 1.1.0 "$RW4" RELEASED
if ! grep -q "${RW1:0:7} " <<< "$(grep '^rw ' <<< "$OUT")"; then pass "pre-range landing is not a row"; else fail "pre-range landing listed"; fi
run "$R" --ref main --apply
expect_rc "backfill --apply" 0
if [[ "$(git -C "$R" tag -l)" == "rw-v1.1.0" ]]; then pass "only rw-v1.1.0 created"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
run "$R" --ref main
expect_rc "dry run after backfill" 0
echo "Case 12e2: the escape from an INVALID run is a hand-cut tag on the next valid version"
R="$(new_repo)"
write_apm "$R" om 1.0.0; commit "$R" a; OM1="$(head_sha "$R")"
write_apm "$R" om 1.1; commit "$R" b
write_apm "$R" om 1.2.0; commit "$R" c; OM3="$(head_sha "$R")"
write_apm "$R" om 1.3.0; commit "$R" d; OM4="$(head_sha "$R")"
write_apm "$R" op 1.0.0; commit "$R" e
(cd "$R" && git tag -a om-v1.0.0 -m x "$OM1")
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "INVALID run blocks --apply for every plugin" 2
if [[ "$(git -C "$R" tag -l)" == "om-v1.0.0" ]]; then pass "nothing created, not even the other plugin's tag"; else fail "tags created: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
(cd "$R" && git tag -a om-v1.2.0 -m "om 1.2.0" "$OM3")
run "$R" --ref main
expect_rc "after the hand-cut tag, only missing tags remain" 1
expect_rows "invalid run no longer wanted" om 2
expect_row "hand-cut start point OK" om 1.2.0 "$OM3" OK
expect_row "next version MISSING" om 1.3.0 "$OM4" MISSING
echo "Case 12u: a git rev-list failure or an empty history exits 2, not a crash"
R="$(new_repo)"
write_apm "$R" rl 1.0.0; commit "$R" a
W="$(mktemp -d)"; CLEANUP_DIRS+=("$W")
REAL_GIT="$(command -v git)"
cat > "$W/git" <<EOF
#!/usr/bin/env bash
if [[ "\$1" == rev-list && " \$* " == *" --reverse "* ]]; then
case "\${FAKE_REVLIST:-}" in
fail) echo "fatal: simulated rev-list failure" >&2; exit 128 ;;
empty) exit 0 ;;
esac
fi
exec "$REAL_GIT" "\$@"
EOF
chmod +x "$W/git"
RC=0; OUT="$(cd "$R" && PATH="$W:$PATH" FAKE_REVLIST=fail bash "$SCRIPT" --ref main 2>&1)" || RC=$?
expect_rc "rev-list failure" 2
if grep -q "git rev-list could not read plugins/rl/apm.yml" <<< "$OUT"; then pass "message names the rev-list failure"; else fail "no rev-list message"; echo "$OUT" | sed 's/^/ /'; fi
RC=0; OUT="$(cd "$R" && PATH="$W:$PATH" FAKE_REVLIST=empty bash "$SCRIPT" --ref main 2>&1)" || RC=$?
expect_rc "no commit carries apm.yml" 2
if grep -q "no commit on its first-parent history carries it" <<< "$OUT"; then pass "message names the empty history"; else fail "no empty-history message"; echo "$OUT" | sed 's/^/ /'; fi
if ! grep -q "unbound\|bad array subscript" <<< "$OUT"; then pass "no shell crash"; else fail "shell crashed"; fi
echo "Case 12v: a glob character in a plugin name is rejected before any pathspec or ref pattern"
R="$(new_repo)"
write_apm "$R" ab 1.0.0; commit "$R" a; AB1="$(head_sha "$R")"
write_apm "$R" "a*" 1.0.0; commit "$R" b
write_apm "$R" ab 1.1.0; commit "$R" c; AB3="$(head_sha "$R")"
(cd "$R" && git tag -a ab-v1.0.0 -m x "$AB1")
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "plugin 'a*' is rejected" 2
if grep -q "plugins/a\*: 'a\*-v<version>' is not a valid tag name (git check-ref-format)" <<< "$OUT"; then pass "message names a* and check-ref-format"; else fail "no preflight message"; echo "$OUT" | sed 's/^/ /'; fi
if ! grep -q "^PLUGIN " <<< "$OUT"; then pass "rejected before any history is read (no table)"; else fail "table printed"; fi
if [[ "$(git -C "$R" tag -l)" == "ab-v1.0.0" ]]; then pass "nothing created"; else fail "tags created: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
run "$R" --ref main --plugin ab
expect_rc "ab alone is unaffected by its glob-named neighbour" 1
expect_rows "ab rows only" ab 2
expect_row "ab 1.0.0 OK" ab 1.0.0 "$AB1" OK
expect_row "ab 1.1.0 MISSING" ab 1.1.0 "$AB3" MISSING
echo "Case 12p: expect_row matches a version's dots literally"
OUT="zz 1x0x0 abcdef0 OK"
if ! grep -Eq "^zz +$(ere_quote 1.0.0) +abcdef0 +OK\$" <<< "$OUT"; then pass "1.0.0 does not match 1x0x0"; else fail "unescaped dots"; fi