Skip to content

Commit 63e5bf6

Browse files
authored
Only use --exclude on name-rev with git >= 2.13 (#12347)
Fix #11917 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 8bdc979 commit 63e5bf6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

modules/git/commit.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222

2323
"github.com/go-git/go-git/v5/plumbing/object"
24+
"github.com/mcuadros/go-version"
2425
)
2526

2627
// Commit represents a git commit.
@@ -468,7 +469,20 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
468469

469470
// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
470471
func (c *Commit) GetBranchName() (string, error) {
471-
data, err := NewCommand("name-rev", "--exclude", "refs/tags/*", "--name-only", "--no-undefined", c.ID.String()).RunInDir(c.repo.Path)
472+
binVersion, err := BinVersion()
473+
if err != nil {
474+
return "", fmt.Errorf("Git version missing: %v", err)
475+
}
476+
477+
args := []string{
478+
"name-rev",
479+
}
480+
if version.Compare(binVersion, "2.13.0", ">=") {
481+
args = append(args, "--exclude", "refs/tags/*")
482+
}
483+
args = append(args, "--name-only", "--no-undefined", c.ID.String())
484+
485+
data, err := NewCommand(args...).RunInDir(c.repo.Path)
472486
if err != nil {
473487
// handle special case where git can not describe commit
474488
if strings.Contains(err.Error(), "cannot describe") {

0 commit comments

Comments
 (0)