diff --git a/mindforge.cronjob/internal/git/git.go b/mindforge.cronjob/internal/git/git.go index cfe962f..5c14344 100644 --- a/mindforge.cronjob/internal/git/git.go +++ b/mindforge.cronjob/internal/git/git.go @@ -121,18 +121,30 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) { continue } + originalFile := file + // Remove first folder from file path file = strings.Join(strings.Split(file, "/")[1:], "/") - // Get the specific diff for this file - cmdDiff := exec.Command("git", "diff", baseCommit, "HEAD", "--", file) + // Note: 'git diff' compares the beginning and end trees, so it has no native concept + // of ignoring intermediate commits. To skip the changes made in "refactor" commits + // without using loops, we use `git log -p` combined with `--invert-grep` to + // natively output the diffs of only the non-refactor commits for this file. + rangeStr := "HEAD" + if baseCommit != "4b825dc642cb6eb9a060e54bf8d69288fbee4904" { + rangeStr = baseCommit + "..HEAD" + } + + cmdDiff := exec.Command("git", "log", "-p", "-i", "--invert-grep", "--grep=refactor", rangeStr, "--", originalFile) cmdDiff.Dir = s.repoDir diffOut, err := cmdDiff.Output() if err != nil { - return nil, fmt.Errorf("failed to get diff for file %s: %w", file, err) + return nil, fmt.Errorf("failed to get diff for file %s: %w", originalFile, err) } - mods[file] = string(diffOut) + if len(diffOut) > 0 { + mods[file] = string(diffOut) + } } return mods, nil