summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-07-28 15:11:05 +0100
committerGitHub <noreply@github.com>2020-07-28 15:11:05 +0100
commit63e5bf6ef7604b542fa77d48d2b70f400cc87a81 (patch)
treea22411af2fef9945c3b1e3435ad02c7dd4fd46f8
parent8bdc9795d8a5aa51bc1295dd1cf57006a5873343 (diff)
downloadgitea-63e5bf6ef7604b542fa77d48d2b70f400cc87a81.tar.gz
gitea-63e5bf6ef7604b542fa77d48d2b70f400cc87a81.zip
Only use --exclude on name-rev with git >= 2.13 (#12347)
Fix #11917 Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r--modules/git/commit.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index b8ff99cdb6..3506b8efe4 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -21,6 +21,7 @@ import (
"strings"
"github.com/go-git/go-git/v5/plumbing/object"
+ "github.com/mcuadros/go-version"
)
// Commit represents a git commit.
@@ -468,7 +469,20 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
func (c *Commit) GetBranchName() (string, error) {
- data, err := NewCommand("name-rev", "--exclude", "refs/tags/*", "--name-only", "--no-undefined", c.ID.String()).RunInDir(c.repo.Path)
+ binVersion, err := BinVersion()
+ if err != nil {
+ return "", fmt.Errorf("Git version missing: %v", err)
+ }
+
+ args := []string{
+ "name-rev",
+ }
+ if version.Compare(binVersion, "2.13.0", ">=") {
+ args = append(args, "--exclude", "refs/tags/*")
+ }
+ args = append(args, "--name-only", "--no-undefined", c.ID.String())
+
+ data, err := NewCommand(args...).RunInDir(c.repo.Path)
if err != nil {
// handle special case where git can not describe commit
if strings.Contains(err.Error(), "cannot describe") {