MCPcopy Create free account
hub / github.com/LegacyCodeHQ/clarity-cli / GetUncommittedFileStats

Function GetUncommittedFileStats

vcs/git/git_stats.go:19–114  ·  view source on GitHub ↗

GetUncommittedFileStats returns statistics (additions/deletions) for uncommitted files Returns a map from relative file paths to their FileStats

(repoPath string)

Source from the content-addressed store, hash-verified

17// GetUncommittedFileStats returns statistics (additions/deletions) for uncommitted files
18// Returns a map from relative file paths to their FileStats
19func GetUncommittedFileStats(repoPath string) (map[string]vcs.FileStats, error) {
20 // Validate the repository path exists
21 if _, err := os.Stat(repoPath); os.IsNotExist(err) {
22 return nil, fmt.Errorf("repository path does not exist: %s", repoPath)
23 }
24
25 // Verify it's a git repository
26 if !isGitRepository(repoPath) {
27 return nil, fmt.Errorf("%s is not a git repository", repoPath)
28 }
29
30 // Get the repository root
31 repoRoot, err := GetRepositoryRoot(repoPath)
32 if err != nil {
33 return nil, fmt.Errorf("failed to get repository root: %w", err)
34 }
35
36 // Run git diff --numstat to get stats for uncommitted changes
37 // This includes both staged and unstaged changes
38 stdout, stderr, err := runGitCommand(repoPath, "diff", "--numstat", "HEAD")
39 if err != nil {
40 return nil, gitCommandError(err, stderr)
41 }
42
43 statusMap, err := getUncommittedFileStatuses(repoPath)
44 if err != nil {
45 return nil, err
46 }
47
48 // Parse the numstat output
49 stats := make(map[string]vcs.FileStats)
50 lines := strings.Split(string(stdout), "\n")
51 for _, line := range lines {
52 line = strings.TrimSpace(line)
53 if line == "" {
54 continue
55 }
56
57 // Format: additions deletions filename
58 parts := strings.Fields(line)
59 if len(parts) < 3 {
60 continue
61 }
62
63 additions := 0
64 deletions := 0
65
66 // Parse additions (may be "-" for binary files)
67 if parts[0] != "-" {
68 additions, _ = strconv.Atoi(parts[0])
69 }
70
71 // Parse deletions (may be "-" for binary files)
72 if parts[1] != "-" {
73 deletions, _ = strconv.Atoi(parts[1])
74 }
75
76 // Handle renamed files

Callers 3

collectFileStatsFunction · 0.92
buildGraphFunction · 0.92

Calls 8

isGitRepositoryFunction · 0.85
GetRepositoryRootFunction · 0.85
runGitCommandFunction · 0.85
gitCommandErrorFunction · 0.85
parseRenamedFilePathFunction · 0.85
isNewStatusFunction · 0.85