MCPcopy Index your code
hub / github.com/MiniCodeMonkey/chief / GetDiffStats

Function GetDiffStats

internal/git/git.go:97–126  ·  view source on GitHub ↗

GetDiffStats returns a short diffstat summary.

(dir string)

Source from the content-addressed store, hash-verified

95
96// GetDiffStats returns a short diffstat summary.
97func GetDiffStats(dir string) (string, error) {
98 branch, err := GetCurrentBranch(dir)
99 if err != nil {
100 return "", err
101 }
102
103 if !IsProtectedBranch(branch) {
104 baseBranch, err := GetDefaultBranch(dir)
105 if err == nil && baseBranch != "" {
106 mergeBase, err := getMergeBase(dir, baseBranch, "HEAD")
107 if err == nil && mergeBase != "" {
108 cmd := exec.Command("git", "diff", "--stat", mergeBase, "HEAD")
109 cmd.Dir = dir
110 output, err := cmd.Output()
111 if err != nil {
112 return "", err
113 }
114 return strings.TrimSpace(string(output)), nil
115 }
116 }
117 }
118
119 cmd := exec.Command("git", "diff", "--stat", "HEAD~10", "HEAD")
120 cmd.Dir = dir
121 output, err := cmd.Output()
122 if err != nil {
123 return "", err
124 }
125 return strings.TrimSpace(string(output)), nil
126}
127
128// GetDiffForCommit returns the diff for a single commit using git show.
129func GetDiffForCommit(dir, commitHash string) (string, error) {

Callers 1

loadDiffMethod · 0.92

Calls 4

GetCurrentBranchFunction · 0.85
IsProtectedBranchFunction · 0.85
GetDefaultBranchFunction · 0.85
getMergeBaseFunction · 0.85

Tested by

no test coverage detected