We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f0ab533 commit d8474d5Copy full SHA for d8474d5
git/git.go
@@ -18,11 +18,13 @@ func VerifyRef(ref string) bool {
18
return err == nil
19
}
20
21
+// CurrentBranch reads the checked-out branch for the git repository
22
func CurrentBranch() (string, error) {
- branchCmd := exec.Command("git", "branch", "--show-current")
23
+ // we avoid using `git branch --show-current` for compatibility with git < 2.22
24
+ branchCmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
25
output, err := utils.PrepareCmd(branchCmd).Output()
26
branchName := firstLine(output)
- if err == nil && branchName == "" {
27
+ if err == nil && branchName == "HEAD" {
28
return "", errors.New("git: not on any branch")
29
30
return branchName, err
0 commit comments