Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Improved Describe.String()
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Lezcano <[email protected]>
  • Loading branch information
Eduardo Lezcano committed Apr 20, 2018
1 parent 0605454 commit 030324a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,14 +1233,25 @@ type Describe struct {
Distance int
// Dirty string to append
Dirty string
// Use <Abbrev> 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.
Expand Down

0 comments on commit 030324a

Please sign in to comment.