-
Notifications
You must be signed in to change notification settings - Fork 1
fix: handle exclude patterns for nested directories #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ga1az
merged 2 commits into
Tyrell-Systems:main
from
Vader-7:fix/nested-exclude-patterns
Apr 13, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package fsutil | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestGetRelativePath(t *testing.T) { | ||
| // Create temp dirs for realistic path testing | ||
| tmpDir := t.TempDir() | ||
| baseDir := filepath.Join(tmpDir, "project") | ||
| nestedDir := filepath.Join(baseDir, "src", "lib") | ||
| similarDir := filepath.Join(tmpDir, "project2", "file.txt") | ||
|
|
||
| if err := os.MkdirAll(nestedDir, 0755); err != nil { | ||
| t.Fatalf("failed to create nested test directory %q: %v", nestedDir, err) | ||
| } | ||
| if err := os.MkdirAll(filepath.Dir(similarDir), 0755); err != nil { | ||
| t.Fatalf("failed to create similar test directory %q: %v", filepath.Dir(similarDir), err) | ||
| } | ||
| if err := os.WriteFile(filepath.Join(nestedDir, "main.go"), []byte("package main"), 0644); err != nil { | ||
| t.Fatalf("failed to create nested test file %q: %v", filepath.Join(nestedDir, "main.go"), err) | ||
| } | ||
| if err := os.WriteFile(similarDir, []byte("hello"), 0644); err != nil { | ||
| t.Fatalf("failed to create similar test file %q: %v", similarDir, err) | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| base string | ||
| target string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "nested file", | ||
| base: baseDir, | ||
| target: filepath.Join(nestedDir, "main.go"), | ||
| expected: filepath.Join("src", "lib", "main.go"), | ||
| }, | ||
| { | ||
| name: "same directory", | ||
| base: baseDir, | ||
| target: baseDir, | ||
| expected: ".", | ||
| }, | ||
| { | ||
| name: "similar prefix should not match", | ||
| base: baseDir, | ||
| target: similarDir, | ||
| expected: "file.txt", // Should fall back to basename, not "2/file.txt" | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := GetRelativePath(tt.base, tt.target) | ||
| if err != nil { | ||
| t.Fatalf("GetRelativePath(%q, %q) returned error: %v", tt.base, tt.target, err) | ||
| } | ||
| if got != tt.expected { | ||
| t.Errorf("GetRelativePath(%q, %q) = %q, want %q", tt.base, tt.target, got, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is slightly misleading: for files, the code checks the parent directory prefix (pathToCheckPrefix), not the full file path. Consider rewording the example to reflect what is actually being compared (e.g., that a file under ".git/" has parentDir ".git/" which matches the pattern).