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
66 changes: 42 additions & 24 deletions cmd/lx/testdata/golden/035_no_ignore_files.golden
Original file line number Diff line number Diff line change
@@ -1,132 +1,148 @@
--- STDOUT ---
[1/24] README.md (2 rows)
[1/29] README.md (2 rows)
---
```markdown
# Project
Documentation here.
```

[2/24] assets/logo.png - binary file skipped (12 B)
[2/29] assets/logo.png - binary file skipped (12 B)
[3/29] bin/data.bin - binary file skipped (4 B)
[4/29] bin/empty.txt (0 rows)

[3/24] configs/custom_sections.yaml (1 rows)
[5/29] configs/custom_sections.yaml (1 rows)
---
```yaml
section_header_template: "*** {{ .Body }} ***\n"
```

[4/24] configs/custom_template.yaml (1 rows)
[6/29] configs/custom_template.yaml (1 rows)
---
```yaml
file_content_template: "File: {{ .Path }}\nContent:\n{{ .Content }}"
```

[5/24] configs/follow.yaml (1 rows)
[7/29] configs/follow.yaml (1 rows)
---
```yaml
follow_symlinks: true
```

[6/24] configs/hidden.yaml (1 rows)
[8/29] configs/hidden.yaml (1 rows)
---
```yaml
show_hidden: true
```

[7/24] configs/no_links.yaml (1 rows)
[9/29] configs/no_links.yaml (1 rows)
---
```yaml
no_file_links: true
```

[8/24] doc/notes.txt (1 rows)
[10/29] doc/notes.txt (1 rows)
---
```text
some notes
```

[9/24] ignore_test/foo.go (1 rows)
[11/29] ignore_test/bar.go (1 rows)
---
```go
package bar
```

[12/29] ignore_test/foo.go (1 rows)
---
```go
package foo
```

[10/24] langs/Dockerfile (1 rows)
[13/29] langs/Dockerfile (1 rows)
---
```dockerfile
FROM scratch
```

[11/24] langs/main.rs (1 rows)
[14/29] langs/main.rs (1 rows)
---
```rust
fn main() {}
```

[12/24] langs/script_no_ext (2 rows)
[15/29] langs/script_no_ext (2 rows)
---
```bash
#!/bin/bash
echo hi
```

[13/24] links/cycle_a/visible.txt (1 rows)
[16/29] links/cycle_a/visible.txt (1 rows)
---
```text
a
```

[14/24] links/cycle_b/visible.txt (1 rows)
[17/29] links/cycle_b/visible.txt (1 rows)
---
```text
b
```

[15/24] links/link_to_main.go (~1 rows)
[18/29] links/link_to_main.go (~1 rows)
---
```go
package main
func main() {}
```

[16/24] links/safe_target/recursion.txt (1 rows)
[19/29] links/safe_target/recursion.txt (1 rows)
---
```text
I am safe
```

[17/24] main.go (2 rows)
[20/29] main.go (2 rows)
---
```go
package main
func main() {}
```

[18/24] main_test.go (2 rows)
[21/29] main_test.go (2 rows)
---
```go
package main
import "testing"
```

[19/24] parent_ignore_test/level1/level2/keep_me.go (1 rows)
[22/29] parent_ignore_test/level1/level2/ignore_me.tmp (1 rows)
---
```
ignore
```

[23/29] parent_ignore_test/level1/level2/keep_me.go (1 rows)
---
```go
package level2
```

[20/24] pkg/util.go (1 rows)
[24/29] pkg/util.go (1 rows)
---
```go
package pkg
```

[21/24] spaces/file with spaces.txt (1 rows)
[25/29] secret/locked.txt - error: open secret/locked.txt: PERMISSION_DENIED

[26/29] spaces/file with spaces.txt (1 rows)
---
```text
content with spaces
```

[22/24] src/large.txt (100 rows)
[27/29] src/large.txt (100 rows)
---
```text
Line xxxxxxxxxx
Expand Down Expand Up @@ -231,14 +247,16 @@ Line xxxxxxxxxx
Line xxxxxxxxxx
```

[23/24] src/script.py (1 rows)
[28/29] src/script.py (1 rows)
---
```python
print('hello')
```

[24/24] /ROOT/content/links/broken_link - error: open /ROOT/content/links/broken_link: FILE_NOT_FOUND
[29/29] /ROOT/content/links/broken_link - error: open /ROOT/content/links/broken_link: FILE_NOT_FOUND


--- STDERR ---
Error: Failed to read file: open /ROOT/content/links/broken_link: FILE_NOT_FOUND (path=/ROOT/content/links/broken_link)
Error: Failed to read file: open secret/locked.txt: PERMISSION_DENIED (path=secret/locked.txt)
Warning: Error accessing path during walk: open secret/locked_dir: PERMISSION_DENIED (path=secret/locked_dir)
1 change: 1 addition & 0 deletions internal/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func processStream(ctx context.Context, parsed *ParsedArgs) error {
)

walker := lx.NewWalker(baseRules, overrideRules)
walker.IgnoreEnabled = cfg.IgnoreEnabled

count := 0

Expand Down
4 changes: 2 additions & 2 deletions pkg/lx/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestProcessor_RenderFile_Slicing(t *testing.T) {
cfg := NewConfig()
engine, _ := CompileTemplates(cfg)
global := GlobalContext{TotalFiles: 1}

proc := newProcessor(engine, global, nil, "markdown")

file := NewBufferInputFile("slice.txt", []byte("1\n2\n3\n4\n5\n"))
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestRender_DataURI(t *testing.T) {
func TestRender_ErrorHandling(t *testing.T) {
cfg := NewConfig()
engine, _ := CompileTemplates(cfg)

proc := newProcessor(engine, GlobalContext{}, nil, "markdown")

file := InputFile{
Expand Down
12 changes: 10 additions & 2 deletions pkg/lx/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ type Rule struct {
type Walker struct {
BaseRules []Rule
OverrideRules []Rule
IgnoreEnabled bool
}

// NewWalker initializes the walker.
func NewWalker(basePatterns, overridePatterns []string) *Walker {
return &Walker{
BaseRules: parseRules(basePatterns, ""),
OverrideRules: parseRules(overridePatterns, ""),
IgnoreEnabled: true,
}
}

Expand Down Expand Up @@ -178,7 +180,10 @@ func (w *Walker) Walk(fsys fs.FS, root string, walkFn fs.WalkDirFunc) error {
}

if !info.IsDir() {
localRules := w.loadIgnoreFiles(fsys, ".")
var localRules []Rule
if w.IgnoreEnabled {
localRules = w.loadIgnoreFiles(fsys, ".")
}
effectiveRules := make([]Rule, 0, len(w.BaseRules)+len(localRules)+len(w.OverrideRules))
effectiveRules = append(effectiveRules, w.BaseRules...)
effectiveRules = append(effectiveRules, localRules...)
Expand All @@ -194,7 +199,10 @@ func (w *Walker) Walk(fsys fs.FS, root string, walkFn fs.WalkDirFunc) error {
}

func (w *Walker) recursiveWalk(fsys fs.FS, dir string, parentRules []Rule, walkFn fs.WalkDirFunc, parentIgnored bool) error {
localRules := w.loadIgnoreFiles(fsys, dir)
var localRules []Rule
if w.IgnoreEnabled {
localRules = w.loadIgnoreFiles(fsys, dir)
}

effectiveRules := make([]Rule, 0, len(parentRules)+len(localRules)+len(w.OverrideRules))
effectiveRules = append(effectiveRules, parentRules...)
Expand Down
Loading