Repository navigation
Conversation
gitignore does not allow a negative rule to re-include a file when one of
its parent directories is excluded, because git never descends into an
excluded directory to discover the rule.
git_ignore_path_is_ignored() walks from the path up towards the workdir
root and returns as soon as a rule matches at any level. Given
dir/
!dir/sub/*
the negative rule matches dir/sub/file.txt itself, so the walk stopped
there and never reached the dir/ rule excluding the parent. git reports
the file as ignored, libgit2 reported it as not ignored.
End the walk only on a positive match. When a negative rule matches, keep
walking up so that an excluded parent takes precedence. A negative rule is
still conclusive when nothing above it is excluded, so rules that exclude
a directory's contents rather than the directory itself, such as "dir/*"
with "!dir/keep.txt", are unaffected.
The workdir iterator used by git_status() is not affected, as it skips
excluded directories rather than testing paths individually.
|
The bug you're fixing is real and your diagnosis of it matches what I measure — the walk stopping at Setup. Three static builds from the same source commit —
The two it fixes are git ignores The reason is the step the patch adds. Which is also why the suite doesn't catch it — the same four rule lines in one file are fine:
Two more things you may want to know, neither of them a criticism of the patch:
I opened neither issue and have no stake here beyond keeping the bench honest. Adapter and corpus: — Midas |
Fixes #7283.
A negative gitignore rule can't re-include a file when one of its parent
directories is excluded, because git never descends into an excluded directory
to find the rule in the first place.
git_ignore_path_is_ignored()doesn'tenforce that.
With this
.gitignore:git treats the file as ignored by the
dir/rule:libgit2 returns 0.
The lookup walks from the path up towards the workdir root and returns at the
first rule that matches at any level.
!dir/sub/*matches the file itself, sothe walk stops there and never gets high enough to see that
dir/excludes theparent.
Now only a positive match ends the walk. If a negative rule matches, the walk
carries on upwards so an excluded parent still wins. A negative rule stays
conclusive when nothing above it is excluded, so
dir/*with!dir/keep.txt,which excludes the directory's contents rather than the directory itself, is
unaffected.
Two notes on scope:
git_status()is not affected. Its workdir iterator skips excluded directoriesinstead of testing paths one at a time, so it already agreed with git here. I
checked that on current
mainboth before and after the change.I compared results against git for the reported case and ten related ones,
covering contents-excluded, a re-included directory, deeper negations, a
negation with nothing excluded above it, and paths that don't exist on disk.
All of them agree.
ignore::path::negative_under_excluded_directoryfails on currentmainandpasses with the change. The other two tests pass either way and are there to
catch an over-correction, since the naive fix breaks
dir/*plus!dir/keep.txt. The full offline suite is clean.