From 4240a04754b64fefbf6d1f1df5b6b8558c88d7ca Mon Sep 17 00:00:00 2001 From: Rootiest Date: Wed, 23 Sep 2026 19:46:16 -0400 Subject: [PATCH] fix(agents-init): clean up stale anchored gitignore patterns on migration --- functions/agents-init.fish | 23 +++++++++++++++++++++++ tests/test-agents-init.fish | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/functions/agents-init.fish b/functions/agents-init.fish index 26ab458..4ac1e98 100644 --- a/functions/agents-init.fish +++ b/functions/agents-init.fish @@ -247,6 +247,29 @@ function agents-init --description 'scaffold AGENTS/ sub-repo with agent spec fi end end + # ── Migrate stale anchored gitignore lines ────────────────────────────── + # A project scaffolded by the old agents-init already has anchored + # /AGENTS.md and/or /CLAUDE.md lines in .gitignore. git check-ignore + # sees those as covering the literal path "AGENTS.md", so the new + # unanchored pattern below would be judged already-covered and never + # added -- leaving any newly discovered subdirectory AGENTS.md with no + # gitignore coverage at all. Strip the stale exact lines first so the + # unanchored pattern always gets a chance to be added. No-op when + # neither stale line is present. + set -l gitignore "$root/.gitignore" + if test -f "$gitignore" + if grep -qxF "/AGENTS.md" "$gitignore" + sed -i '/^\/AGENTS\.md$/d' "$gitignore" + set changed 1 + test $verbose -eq 1; and echo "$c_warn→ Removed stale /AGENTS.md line from .gitignore$c_reset" + end + if grep -qxF "/CLAUDE.md" "$gitignore" + sed -i '/^\/CLAUDE\.md$/d' "$gitignore" + set changed 1 + test $verbose -eq 1; and echo "$c_warn→ Removed stale /CLAUDE.md line from .gitignore$c_reset" + end + end + # ── .gitignore ──────────────────────────────────────────────────────── # Unanchored: matches AGENTS.md at every depth, so a newly # discovered subdirectory needs no additional gitignore entry. diff --git a/tests/test-agents-init.fish b/tests/test-agents-init.fish index 34e3581..e0a319b 100644 --- a/tests/test-agents-init.fish +++ b/tests/test-agents-init.fish @@ -199,5 +199,21 @@ check "inversion fix: mirror CLAUDE.md gone" false (test -e $e2/AGENTS/docs/CLAU check "inversion fix: project docs/AGENTS.md relinked directly" ../AGENTS/docs/AGENTS.md (readlink $e2/docs/AGENTS.md) check "inversion fix: project docs/CLAUDE.md gone" false (test -e $e2/docs/CLAUDE.md; and echo true; or echo false) +echo "" +echo "== agents-init: stale anchored gitignore lines migrated ==" + +set -l e3 (new_repo) +mkdir -p $e3/AGENTS +echo real-agents >$e3/AGENTS/AGENTS.md +ln -s AGENTS/AGENTS.md $e3/AGENTS.md +printf '%s\n' AGENTS/ "/AGENTS.md" "/CLAUDE.md" >$e3/.gitignore +pushd $e3 >/dev/null +set -l ercD (agents-init --agents --silent 2>/dev/null; echo $status) +popd >/dev/null +check "stale gitignore: exits 0" 0 "$ercD" +check "stale gitignore: anchored /AGENTS.md line removed" false (grep -qxF '/AGENTS.md' $e3/.gitignore; and echo true; or echo false) +check "stale gitignore: anchored /CLAUDE.md line removed" false (grep -qxF '/CLAUDE.md' $e3/.gitignore; and echo true; or echo false) +check "stale gitignore: unanchored AGENTS.md pattern present" true (grep -qxF 'AGENTS.md' $e3/.gitignore; and echo true; or echo false) + cleanup report