libgit2 applies core.excludesFile/info.exclude last, inverting git's ignore precedence, so a repo !re-include loses to a global exclude
Symptom#
rgit status --short omits AGENTS.md (or any file a global excludes file names) and rgit add AGENTS.md errors "pathspec contains ignored file", while rgit check-ignore and real git both treat it as untracked. Repro: ~/.config/git/ignore contains AGENTS.md, repo .gitignore has !AGENTS.md, file AGENTS.md exists. libgit2's is_path_ignored, statuses() and add_all all wrongly report it ignored.
Cause#
In libgit2's src/libgit2/ignore.c git_ignore__lookup, the global excludes (.git/info/exclude and core.excludesFile) are processed LAST, after the per-directory .gitignore files. Git's real precedence is lowest-to-highest: core.excludesFile < .git/info/exclude < parent .gitignore < own .gitignore, and a later !pattern re-includes a path an earlier source excluded (unless a parent dir is excluded). libgit2 does it backwards, so a repo .gitignore's !AGENTS.md cannot rescue a file the global excludes name.
Fix#
Stop trusting libgit2's ignore decisions. Add a matcher (crates/rgit-git/src/ignored.rs) that re-implements git's precedence: per-dir .gitignore (deepest dir first), then .git/info/exclude, then core.excludesFile (resolved from config, else $XDG_CONFIG_HOME/git/ignore), last-matching-line wins via the ignore crate's GitignoreBuilder, and an excluded parent directory ignores everything under it (checked recursively). Route every ignore-filtering point through crate::ignored::is_ignored instead of repo.is_path_ignored: status (wt_status walker + status_walk collect_entries/merge_entries with include_ignored(true) then reclassifying untracked via untracked_instead), add (FORCE flag + a callback that skips genuinely-ignored files, plus an explicit per-path ignored error), clean, sparse clean_folders, folder_files, paths_ignored, and check-ignore. Regression tests set core.excludesFile in the test repo to a fake file so the real home folder is never read.
Evidence#
rgit 2026. rgit had this bug with a global AGENTS.md; libgit2-sys 0.18.8+1.9.7 verified in ignore.c that global excludes are applied last. The read physical cause is libgit2's ignore lookup order, not rgit's reading of the excludes file. Fixed and covered by crates/rgit-cli/tests/it/global_ignore.rs (4 cases) and crates/rgit-git/tests/it/status.rs global_exclude_reincluded_shows_untracked_and_stages.