• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valksor / kvelmo / 23471163553

24 Mar 2026 02:51AM UTC coverage: 49.867% (-1.4%) from 51.3%
23471163553

push

github

k0d3r1s
Update project config and gap analysis commands

Update CLAUDE.md with new CLI commands and package descriptions. Revise
AGENTS.md with current architecture guidance. Add CodeRabbit config
rule. Update lefthook pre-commit hook. Refresh all gap analysis
commands with current feature inventory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

811 of 1374 branches covered (59.02%)

Branch coverage included in aggregate %.

22001 of 44372 relevant lines covered (49.58%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/pkg/git/diff_hunks.go
1
package git
2

3
import (
4
        "context"
5
        "fmt"
6
        "regexp"
7
        "strconv"
8
        "strings"
9
)
10

11
// hunkHeaderRe matches unified diff hunk headers like @@ -a,b +c,d @@.
12
// We capture the new-side start line and optional count.
13
var hunkHeaderRe = regexp.MustCompile(`^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@`)
14

15
// DiffHunks returns the changed line ranges per file between the given base
16
// ref and HEAD. Each entry maps a file path (relative to repo root) to a
17
// list of [start, end] pairs representing inclusive line ranges that were
18
// added or modified.
19
//
20
// The base argument is typically a branch name like "main" or "origin/main".
21
// It uses the three-dot diff (base...HEAD) to show only changes introduced
22
// on the current branch since it diverged from base.
23
func (r *Repository) DiffHunks(ctx context.Context, base string) (map[string][][2]int, error) {
×
24
        out, err := r.run(ctx, "diff", "--unified=0", base+"...HEAD")
×
25
        if err != nil {
×
26
                return nil, fmt.Errorf("diff hunks: %w", err)
×
27
        }
×
28

29
        return parseUnifiedDiffHunks(out), nil
×
30
}
31

32
// parseUnifiedDiffHunks parses `git diff --unified=0` output and extracts
33
// new-side line ranges per file.
34
func parseUnifiedDiffHunks(diffOutput string) map[string][][2]int {
1✔
35
        result := make(map[string][][2]int)
1✔
36

1✔
37
        var currentFile string
1✔
38

1✔
39
        for _, line := range strings.Split(diffOutput, "\n") {
2✔
40
                if strings.HasPrefix(line, "+++ b/") {
2✔
41
                        currentFile = strings.TrimPrefix(line, "+++ b/")
1✔
42

1✔
43
                        continue
1✔
44
                }
45

46
                if currentFile == "" {
2✔
47
                        continue
1✔
48
                }
49

50
                matches := hunkHeaderRe.FindStringSubmatch(line)
1✔
51
                if matches == nil {
2✔
52
                        continue
1✔
53
                }
54

55
                start, err := strconv.Atoi(matches[1])
1✔
56
                if err != nil {
1✔
57
                        continue
×
58
                }
59

60
                count := 1
1✔
61
                if matches[2] != "" {
2✔
62
                        count, err = strconv.Atoi(matches[2])
1✔
63
                        if err != nil {
1✔
64
                                continue
×
65
                        }
66
                }
67

68
                // A count of 0 means pure deletion — no new lines to flag.
69
                if count == 0 {
2✔
70
                        continue
1✔
71
                }
72

73
                end := start + count - 1
1✔
74
                result[currentFile] = append(result[currentFile], [2]int{start, end})
1✔
75
        }
76

77
        return result
1✔
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc