diff --git a/repository.go b/repository.go index 0f179b664..213f9f19a 100644 --- a/repository.go +++ b/repository.go @@ -1233,14 +1233,25 @@ type Describe struct { Distance int // Dirty string to append Dirty string + // Use digits to display SHA-ls + Abbrev int } func (d *Describe) String() string { - return fmt.Sprintf("%v-%v-%v-%v", - d.Tag.Name().Short(), - d.Distance, - d.Reference.Hash().String()[0:8], - d.Dirty) + var s []string + + if d.Tag != nil{ + s = append(s, d.Tag.Name().Short()) + } + if d.Distance > 0 { + s = append(s, fmt.Sprint(d.Distance)) + } + s = append(s, d.Reference.Hash().String()[0:d.Abbrev]) + if d.Dirty != "" { + s = append(s, d.Dirty) + } + + return strings.Join(s, "-") } // Describe just like the `git describe` command will return a Describe struct for the hash passed.