github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/util/git/describe.go (about)

     1  package git
     2  
     3  import (
     4  	"github.com/metux/go-metabuild/util/cmd"
     5  )
     6  
     7  func Describe(tags bool, all bool, exclude []string, match []string) (string, error) {
     8  	c := append(gitCmd, "describe")
     9  
    10  	if tags {
    11  		c = append(c, "--tags")
    12  	}
    13  
    14  	if all {
    15  		c = append(c, "--all")
    16  	}
    17  
    18  	for _, ex := range exclude {
    19  		c = append(c, "--exclude", ex)
    20  	}
    21  
    22  	for _, ex := range match {
    23  		c = append(c, "--match", ex)
    24  	}
    25  
    26  	return cmd.RunOutOne(c, true)
    27  }
    28  
    29  func PkgVersion(tags bool, all bool, exclude []string, match []string) (string, error) {
    30  	ver, err := Describe(tags, all, exclude, match)
    31  	if err == nil {
    32  		if len(ver) > 1 && ver[0] == 'v' {
    33  			ver = ver[1:]
    34  		}
    35  	}
    36  	return ver, err
    37  }