Skip to content

Commit 5052c49

Browse files
committed
fix: refine .git directory exclusion regex
Improved the regex pattern used for matching the .git directory to exclude cases such as nested .git folders and handle different path separators on various operating systems. Removed the redundant check in GatherFiles function as the new regex pattern covers all cases for .git directory exclusion.
1 parent 1cc5841 commit 5052c49

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

cmd/cwc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func gatherContext(opts *chatOptions) ([]filetree.File, *filetree.FileNode, erro
499499
}
500500

501501
if excludeGitDirFlag {
502-
gitDirMatcher, err := pathmatcher.NewRegexPathMatcher(`^.*\.git$`)
502+
gitDirMatcher, err := pathmatcher.NewRegexPathMatcher(`^\.git(/|\\)`)
503503
if err != nil {
504504
return nil, nil, fmt.Errorf("error creating git directory matcher: %w", err)
505505
}

pkg/filetree/filetree.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ func GatherFiles(opts *FileGatherOptions) ([]File, *FileNode, error) { //nolint:
4747
return err
4848
}
4949

50-
// start by skipping the .git directory
51-
if strings.HasPrefix(path, ".git/") {
52-
return nil
53-
}
54-
5550
normalizedPath := filepath.ToSlash(path)
5651
if !includeMatcher.Match(normalizedPath) || info.IsDir() || excludeMatcher.Match(normalizedPath) {
5752
return nil

0 commit comments

Comments
 (0)