diff --git a/functions/_agents_init_ensure_gitignore.fish b/functions/_agents_init_ensure_gitignore.fish index 724af70..f1f5549 100644 --- a/functions/_agents_init_ensure_gitignore.fish +++ b/functions/_agents_init_ensure_gitignore.fish @@ -7,7 +7,7 @@ # DESCRIPTION # Appends any patterns not already covered by the project's .gitignore. # Uses git check-ignore for accurate rule matching (catches wildcards -# and parent-dir globs). Falls back to a plain string search when the +# and parent-dir globs). Falls back to a whole-line string search when the # root is not a git repository. Leading / is stripped from each pattern # before the path-based check so root-anchored patterns (e.g. /AGENTS.md) # are matched correctly. @@ -58,7 +58,9 @@ function _agents_init_ensure_gitignore git -C "$root" check-ignore -q --no-index "$check_path" 2>/dev/null and set already 1 else if test -f "$gitignore" - grep -qF "$pattern" "$gitignore" + # Whole-line match: a substring match treats a negation line + # such as "!AGENTS/foo" as covering the pattern "AGENTS/". + grep -qxF "$pattern" "$gitignore" and set already 1 end if test $already -eq 0 diff --git a/tests/test-agents-vault.fish b/tests/test-agents-vault.fish index 823d458..972b0bc 100644 --- a/tests/test-agents-vault.fish +++ b/tests/test-agents-vault.fish @@ -2075,6 +2075,16 @@ agents-init --silent 2>/dev/null popd >/dev/null check "an existing AGENTS.md still scaffolds" true (test -d $plainagents/AGENTS; and echo true; or echo false) +# ──────────────────── gitignore fallback anchoring ────────────────────── +echo "" +echo "== gitignore fallback anchoring ==" + +set -l ng (mktemp -d) +set -ga TMPDIRS $ng +printf '!AGENTS/foo\n' >$ng/.gitignore +_agents_init_ensure_gitignore $ng "test" "AGENTS/" >/dev/null +check "negation does not count as ignored" true (grep -qx 'AGENTS/' $ng/.gitignore; and echo true; or echo false) + # ──────────────────────── hermeticity assertion ──────────────────────── # The whole suite must never have touched the real global agent state. The # failure this guards is specific: a global-memory sync with no test