MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / GetDiff

Function GetDiff

internal/git/git.go:75–94  ·  view source on GitHub ↗

GetDiff returns the git diff output for the working directory. It shows the diff between the current branch and its merge base with the default branch. If on main/master or if merge-base fails, it shows the last few commits' diff.

(dir string)

Source from the content-addressed store, hash-verified

73// It shows the diff between the current branch and its merge base with the default branch.
74// If on main/master or if merge-base fails, it shows the last few commits' diff.
75func GetDiff(dir string) (string, error) {
76 branch, err := GetCurrentBranch(dir)
77 if err != nil {
78 return "", err
79 }
80
81 // If on a feature branch, diff against merge-base with main/master
82 if !IsProtectedBranch(branch) {
83 baseBranch, err := GetDefaultBranch(dir)
84 if err == nil && baseBranch != "" {
85 mergeBase, err := getMergeBase(dir, baseBranch, "HEAD")
86 if err == nil && mergeBase != "" {
87 return getDiffOutput(dir, mergeBase, "HEAD")
88 }
89 }
90 }
91
92 // Fallback: show diff of recent commits (last 10)
93 return getDiffOutput(dir, "HEAD~10", "HEAD")
94}
95
96// GetDiffStats returns a short diffstat summary.
97func GetDiffStats(dir string) (string, error) {

Callers 1

loadDiffMethod · 0.92

Calls 5

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

Tested by

no test coverage detected