Skip to content

Commit

Permalink
revert: remove path conversion in ShouldDirBeIgnored
Browse files Browse the repository at this point in the history
  • Loading branch information
s0up4200 committed Jan 16, 2025
1 parent 947e42b commit 117595f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
23 changes: 3 additions & 20 deletions internal/common/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,11 @@ func (ui *UI) SetIgnoreHidden(value bool) {

// ShouldDirBeIgnored returns true if given path should be ignored
func (ui *UI) ShouldDirBeIgnored(name, path string) bool {
if _, shouldIgnore := ui.IgnoreDirPaths[path]; shouldIgnore {
_, shouldIgnore := ui.IgnoreDirPaths[path]
if shouldIgnore {
log.Printf("Directory %s ignored", path)
return true
}

if filepath.IsAbs(path) {
if relPath, err := filepath.Rel("/", path); err == nil {
if _, shouldIgnore := ui.IgnoreDirPaths[relPath]; shouldIgnore {
log.Printf("Directory %s ignored (matched relative path %s)", path, relPath)
return true
}
}
} else {
if absPath, err := filepath.Abs(path); err == nil {
if _, shouldIgnore := ui.IgnoreDirPaths[absPath]; shouldIgnore {
log.Printf("Directory %s ignored (matched absolute path %s)", path, absPath)
return true
}
}
}

return false
return shouldIgnore
}

// ShouldDirBeIgnoredUsingPattern returns true if given path should be ignored
Expand Down
12 changes: 0 additions & 12 deletions internal/common/ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,6 @@ func TestIgnoreByRelativePath(t *testing.T) {
assert.False(t, shouldBeIgnored("xxx", "test_dir/xxx"))
}

func TestIgnoreByAbsPathWithRelativeMatch(t *testing.T) {
ui := &common.UI{}
absPath, err := filepath.Abs("test_dir/abc")
assert.Nil(t, err)
ui.SetIgnoreDirPaths([]string{absPath})
shouldBeIgnored := ui.CreateIgnoreFunc()

assert.True(t, shouldBeIgnored("abc", absPath))
assert.True(t, shouldBeIgnored("abc", "test_dir/abc"))
assert.False(t, shouldBeIgnored("xxx", "test_dir/xxx"))
}

func TestIgnoreByRelativePattern(t *testing.T) {
ui := &common.UI{}
err := ui.SetIgnoreDirPatterns([]string{"test_dir/[abc]+"})
Expand Down

0 comments on commit 117595f

Please sign in to comment.