fix(agents-init): clean up stale anchored gitignore patterns on migration

This commit is contained in:
2026-09-23 19:46:16 -04:00
parent ecfb93a818
commit 4240a04754
2 changed files with 39 additions and 0 deletions
+23
View File
@@ -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.
+16
View File
@@ -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