GetCurrentBranch returns the current git branch name for a directory.
(dir string)
| 9 | |
| 10 | // GetCurrentBranch returns the current git branch name for a directory. |
| 11 | func GetCurrentBranch(dir string) (string, error) { |
| 12 | cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") |
| 13 | cmd.Dir = dir |
| 14 | output, err := cmd.Output() |
| 15 | if err != nil { |
| 16 | return "", err |
| 17 | } |
| 18 | return strings.TrimSpace(string(output)), nil |
| 19 | } |
| 20 | |
| 21 | // IsProtectedBranch returns true if the branch name is main or master. |
| 22 | func IsProtectedBranch(branch string) bool { |
no outgoing calls