Skip to content

Commit 274dec6

Browse files
committed
🐛 Fix .git exclusion pattern to allow .github files
Update regex pattern to exclude only .git directory while preserving .github files like workflows and templates. - Change pattern from '\.git' to '(^|/)\.git(/|$)' for precise matching - Add comprehensive test coverage for both exclusion and inclusion cases - Fixes issue where .github directory was incorrectly filtered out
1 parent 2e35c7b commit 274dec6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/file_analyzers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl FileAnalyzer for DefaultAnalyzer {
171171
pub fn should_exclude_file(path: &str) -> bool {
172172
log_debug!("Checking if file should be excluded: {}", path);
173173
let exclude_patterns = vec![
174-
(String::from(r"\.git"), false),
174+
(String::from(r"(^|/)\.git(/|$)"), false), // Only exclude .git directory, not .github
175175
(String::from(r"\.svn"), false),
176176
(String::from(r"\.hg"), false),
177177
(String::from(r"\.DS_Store"), false),

tests/file_analyzers_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use git_iris::context::{ChangeType, StagedFile};
22
use git_iris::file_analyzers::get_analyzer;
3+
use git_iris::file_analyzers::should_exclude_file;
34

45
#[test]
56
fn test_rust_analyzer() {
@@ -622,3 +623,22 @@ fn test_generic_text_analyzer() {
622623
assert!(tags_analysis.contains("servlet"));
623624
assert!(tags_analysis.contains("filter"));
624625
}
626+
627+
#[test]
628+
fn test_github_files_not_excluded() {
629+
// .github files should NOT be excluded
630+
assert!(!should_exclude_file(".github/workflows/ci.yml"));
631+
assert!(!should_exclude_file(".github/cicd.yml"));
632+
assert!(!should_exclude_file(".github/ISSUE_TEMPLATE.md"));
633+
assert!(!should_exclude_file("project/.github/workflows/test.yml"));
634+
635+
// .git directory should still be excluded
636+
assert!(should_exclude_file(".git/config"));
637+
assert!(should_exclude_file(".git/objects/abc123"));
638+
assert!(should_exclude_file("project/.git/HEAD"));
639+
640+
// Other git-containing paths should not be excluded
641+
assert!(!should_exclude_file("my-git-project/file.txt"));
642+
assert!(!should_exclude_file("gitignore.txt"));
643+
assert!(!should_exclude_file("digital-art.png"));
644+
}

0 commit comments

Comments
 (0)