8 "github.com/stretchr/testify/require"
11func TestCrushIgnore(t *testing.T) {
12 tempDir := t.TempDir()
16 require.NoError(t, os.WriteFile("test1.txt", []byte("test"), 0o644))
17 require.NoError(t, os.WriteFile("test2.log", []byte("test"), 0o644))
18 require.NoError(t, os.WriteFile("test3.tmp", []byte("test"), 0o644))
20 // Create a .crushignore file that ignores .log files
21 require.NoError(t, os.WriteFile(".crushignore", []byte("*.log\n"), 0o644))
23 dl := NewDirectoryLister(tempDir)
24 require.True(t, dl.shouldIgnore("test2.log", nil), ".log files should be ignored")
25 require.False(t, dl.shouldIgnore("test1.txt", nil), ".txt files should not be ignored")
26 require.True(t, dl.shouldIgnore("test3.tmp", nil), ".tmp files should be ignored by common patterns")
29func TestShouldExcludeFile(t *testing.T) {
32 // Create a temporary directory structure for testing
33 tempDir := t.TempDir()
35 // Create directories that should be ignored
36 nodeModules := filepath.Join(tempDir, "node_modules")
37 target := filepath.Join(tempDir, "target")
38 customIgnored := filepath.Join(tempDir, "custom_ignored")
39 normalDir := filepath.Join(tempDir, "src")
41 for _, dir := range []string{nodeModules, target, customIgnored, normalDir} {
42 if err := os.MkdirAll(dir, 0o755); err != nil {
43 t.Fatalf("Failed to create directory %s: %v", dir, err)
47 // Create .gitignore file
48 gitignoreContent := "node_modules/\ntarget/\n"
49 if err := os.WriteFile(filepath.Join(tempDir, ".gitignore"), []byte(gitignoreContent), 0o644); err != nil {
50 t.Fatalf("Failed to create .gitignore: %v", err)
53 // Create .crushignore file
54 crushignoreContent := "custom_ignored/\n"
55 if err := os.WriteFile(filepath.Join(tempDir, ".crushignore"), []byte(crushignoreContent), 0o644); err != nil {
56 t.Fatalf("Failed to create .crushignore: %v", err)
59 // Test that ignored directories are properly ignored
60 require.True(t, ShouldExcludeFile(tempDir, nodeModules), "Expected node_modules to be ignored by .gitignore")
61 require.True(t, ShouldExcludeFile(tempDir, target), "Expected target to be ignored by .gitignore")
62 require.True(t, ShouldExcludeFile(tempDir, customIgnored), "Expected custom_ignored to be ignored by .crushignore")
64 // Test that normal directories are not ignored
65 require.False(t, ShouldExcludeFile(tempDir, normalDir), "Expected src directory to not be ignored")
67 // Test that the workspace root itself is not ignored
68 require.False(t, ShouldExcludeFile(tempDir, tempDir), "Expected workspace root to not be ignored")
71func TestShouldExcludeFileHierarchical(t *testing.T) {
74 // Create a nested directory structure for testing hierarchical ignore
75 tempDir := t.TempDir()
77 // Create nested directories
78 subDir := filepath.Join(tempDir, "subdir")
79 nestedNormal := filepath.Join(subDir, "normal_nested")
81 for _, dir := range []string{subDir, nestedNormal} {
82 if err := os.MkdirAll(dir, 0o755); err != nil {
83 t.Fatalf("Failed to create directory %s: %v", dir, err)
87 // Create .crushignore in subdir that ignores normal_nested
88 subCrushignore := "normal_nested/\n"
89 if err := os.WriteFile(filepath.Join(subDir, ".crushignore"), []byte(subCrushignore), 0o644); err != nil {
90 t.Fatalf("Failed to create subdir .crushignore: %v", err)
93 // Test hierarchical ignore behavior - this should work because the .crushignore is in the parent directory
94 require.True(t, ShouldExcludeFile(tempDir, nestedNormal), "Expected normal_nested to be ignored by subdir .crushignore")
95 require.False(t, ShouldExcludeFile(tempDir, subDir), "Expected subdir itself to not be ignored")
98func TestShouldExcludeFileCommonPatterns(t *testing.T) {
101 tempDir := t.TempDir()
103 // Create directories that should be ignored by common patterns
104 commonIgnored := []string{
105 filepath.Join(tempDir, ".git"),
106 filepath.Join(tempDir, "node_modules"),
107 filepath.Join(tempDir, "__pycache__"),
108 filepath.Join(tempDir, "target"),
109 filepath.Join(tempDir, ".vscode"),
112 for _, dir := range commonIgnored {
113 if err := os.MkdirAll(dir, 0o755); err != nil {
114 t.Fatalf("Failed to create directory %s: %v", dir, err)
118 // Test that common patterns are ignored even without explicit ignore files
119 for _, dir := range commonIgnored {
120 require.True(t, ShouldExcludeFile(tempDir, dir), "Expected %s to be ignored by common patterns", filepath.Base(dir))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list