CommitCount returns the number of commits on branch that are not on the default branch. Returns 0 if the count cannot be determined.
(repoDir, branch string)
| 52 | // CommitCount returns the number of commits on branch that are not on the default branch. |
| 53 | // Returns 0 if the count cannot be determined. |
| 54 | func CommitCount(repoDir, branch string) int { |
| 55 | defaultBranch, err := GetDefaultBranch(repoDir) |
| 56 | if err != nil { |
| 57 | return 0 |
| 58 | } |
| 59 | cmd := exec.Command("git", "rev-list", "--count", defaultBranch+".."+branch) |
| 60 | cmd.Dir = repoDir |
| 61 | out, err := cmd.Output() |
| 62 | if err != nil { |
| 63 | return 0 |
| 64 | } |
| 65 | count, err := strconv.Atoi(strings.TrimSpace(string(out))) |
| 66 | if err != nil { |
| 67 | return 0 |
| 68 | } |
| 69 | return count |
| 70 | } |
| 71 | |
| 72 | // GetDiff returns the git diff output for the working directory. |
| 73 | // It shows the diff between the current branch and its merge base with the default branch. |
no test coverage detected