GetDiffStats returns a short diffstat summary.
(dir string)
| 95 | |
| 96 | // GetDiffStats returns a short diffstat summary. |
| 97 | func 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. |
| 129 | func GetDiffForCommit(dir, commitHash string) (string, error) { |
no test coverage detected