Ignore file rename / remove operations as they don't contribute to the codebase. (#1)

This commit is contained in:
2025-12-16 19:11:25 +00:00
committed by GitHub
parent 8423b6ada1
commit aedcf87338
3 changed files with 47 additions and 0 deletions
+7
View File
@@ -63,3 +63,10 @@ func IsDocumentationFile(filename string) bool {
func IsMeaningfulLine(line string) bool {
return !IsWhitespaceLine(line) && !IsCommentLine(line)
}
// IsRenameOrMove checks if a file change represents a rename or move operation
// rather than actual content modification. A rename/move is detected when both
// the source (fromName) and destination (toName) paths exist and differ.
func IsRenameOrMove(fromName, toName string) bool {
return fromName != "" && toName != "" && fromName != toName
}
+35
View File
@@ -167,3 +167,38 @@ func TestIsMeaningfulLine(t *testing.T) {
})
}
}
func TestIsRenameOrMove(t *testing.T) {
tests := []struct {
name string
fromName string
toName string
expected bool
}{
// Rename/move operations - should return true
{"simple rename", "old.go", "new.go", true},
{"move to subdirectory", "file.go", "pkg/file.go", true},
{"move from subdirectory", "pkg/file.go", "file.go", true},
{"rename in subdirectory", "pkg/old.go", "pkg/new.go", true},
{"move between directories", "src/file.go", "lib/file.go", true},
{"complex path rename", "internal/api/v1/handler.go", "internal/api/v2/handler.go", true},
// NOT rename/move - should return false
{"new file", "", "new.go", false},
{"deleted file", "old.go", "", false},
{"modify same file", "file.go", "file.go", false},
{"both empty", "", "", false},
{"same path different case is not rename", "File.go", "File.go", false},
// Edge cases
{"whitespace in path rename", "my file.go", "my-file.go", true},
{"deeply nested rename", "a/b/c/d/e/f.go", "a/b/c/d/e/g.go", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := IsRenameOrMove(tt.fromName, tt.toName)
assert.Equal(t, tt.expected, result, "IsRenameOrMove(%q, %q)", tt.fromName, tt.toName)
})
}
}
+5
View File
@@ -397,6 +397,11 @@ func (r *Repository) getCommitStats(c *object.Commit, testPatterns []string) com
filesSet := make(map[string]bool)
for _, change := range changes {
// Skip rename/move operations - they don't represent actual code contribution
if diff.IsRenameOrMove(change.From.Name, change.To.Name) {
continue
}
// Get the file path
var filePath string
if change.To.Name != "" {