Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions internal/ignore/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (r *Rules) AddDefaults() {
r.parseRule("**/.agentuity-*")
r.parseRule("**/biome.json")
r.parseRule("**/.DS_Store")
r.parseRule("!setup.sh") // Explicitly don't ignore setup.sh
}

// Add a rule to the ignore set.
Expand Down Expand Up @@ -152,6 +153,7 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
}

var fullWildcard bool
var matched bool

for n, p := range r.patterns {
if p.match == nil {
Expand All @@ -172,34 +174,39 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
if p.negate {
// if full wildcard, we inverse the negation to only match files that match the following rules
if fullWildcard {
if p.mustDir && fi.IsDir() {
if p.mustDir && fi != nil && fi.IsDir() {
return false
}
if p.match(path, fi) {
return false
}
} else {
// otherwise, we only match files that don't match the rule
if p.mustDir && !fi.IsDir() {
return true
// For negation rules, if the path matches the pattern, it should NOT be ignored
if p.mustDir && fi != nil && !fi.IsDir() {
continue
}
if !p.match(path, fi) {
return true
if p.match(path, fi) {
return false
}
}
continue
}

// If the rule is looking for directories, and this is not a directory,
// skip it.
if p.mustDir && !fi.IsDir() {
if p.mustDir && fi != nil && !fi.IsDir() {
continue
}
if p.match(path, fi) {
return true
matched = true
// Don't return immediately - keep checking for negation rules
}
}
return fullWildcard

if fullWildcard {
return true
}
return matched
}

// parseRule parses a rule string and creates a pattern, which is then stored in the Rules object.
Expand Down
4 changes: 3 additions & 1 deletion internal/ignore/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ func TestRules(t *testing.T) {
assert.True(t, rules.Ignore("/Users/foobar/example/.foo.swp", nil))
assert.True(t, rules.Ignore("/Users/foobar/example/src/__test__/test_bar.py", nil))
assert.True(t, rules.Ignore("/Users/foobar/example/.agentuity-12345", nil))
assert.False(t, rules.Ignore("/Users/foobar/setup.sh", nil))
}

func TestNegateRules(t *testing.T) {
rules := Empty()
rules.AddDefaults()
rules.Add("!**/foo.py")
rules.Add("**/*.py") // First ignore all Python files
rules.Add("!**/foo.py") // Then negate foo.py specifically
assert.False(t, rules.Ignore("/Users/foobar/example/src/foo.py", nil))
assert.False(t, rules.Ignore("foo.py", nil))
assert.True(t, rules.Ignore("bar.py", nil))
Expand Down
Loading