MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestNestedGitignoreDirectoryIgnore

Function TestNestedGitignoreDirectoryIgnore

scanner/walker_test.go:514–569  ·  view source on GitHub ↗

TestNestedGitignoreDirectoryIgnore verifies that directory patterns skip the entire directory (not just pattern-match files inside)

(t *testing.T)

Source from the content-addressed store, hash-verified

512// TestNestedGitignoreDirectoryIgnore verifies that directory patterns
513// skip the entire directory (not just pattern-match files inside)
514func TestNestedGitignoreDirectoryIgnore(t *testing.T) {
515 tmpDir := t.TempDir()
516
517 // Create: root/.gitignore with "ignored_dir/"
518 // Create: root/ignored_dir/deeply/nested/file.go
519 // The entire ignored_dir should be skipped
520
521 if err := os.MkdirAll(filepath.Join(tmpDir, "ignored_dir/deeply/nested"), 0755); err != nil {
522 t.Fatal(err)
523 }
524 if err := os.MkdirAll(filepath.Join(tmpDir, "visible_dir/sub"), 0755); err != nil {
525 t.Fatal(err)
526 }
527
528 if err := os.WriteFile(filepath.Join(tmpDir, ".gitignore"), []byte("ignored_dir/\n"), 0644); err != nil {
529 t.Fatal(err)
530 }
531 if err := os.WriteFile(filepath.Join(tmpDir, "ignored_dir/deeply/nested/file.go"), []byte("pkg"), 0644); err != nil {
532 t.Fatal(err)
533 }
534 if err := os.WriteFile(filepath.Join(tmpDir, "visible_dir/sub/file.go"), []byte("pkg"), 0644); err != nil {
535 t.Fatal(err)
536 }
537 if err := os.WriteFile(filepath.Join(tmpDir, "root.go"), []byte("pkg"), 0644); err != nil {
538 t.Fatal(err)
539 }
540
541 cache := NewGitIgnoreCache(tmpDir)
542 files, err := ScanFiles(tmpDir, cache, nil, nil)
543 if err != nil {
544 t.Fatalf("ScanFiles failed: %v", err)
545 }
546
547 foundPaths := make(map[string]bool)
548 for _, f := range files {
549 foundPaths[f.Path] = true
550 }
551
552 // Should include visible files
553 if !foundPaths["root.go"] {
554 t.Error("Should include root.go")
555 }
556 if !foundPaths[filepath.Join("visible_dir", "sub", "file.go")] {
557 t.Error("Should include visible_dir/sub/file.go")
558 }
559
560 // Should NOT include anything from ignored_dir
561 if foundPaths[filepath.Join("ignored_dir", "deeply", "nested", "file.go")] {
562 t.Error("Should ignore ignored_dir/deeply/nested/file.go")
563 }
564
565 // Total: .gitignore, root.go, visible_dir/sub/file.go = 3 files
566 if len(files) != 3 {
567 t.Errorf("Expected 3 files, got %d: %v", len(files), foundPaths)
568 }
569}
570
571func TestMatchesPattern(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewGitIgnoreCacheFunction · 0.85
ScanFilesFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected