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 <eduardo.lezcano@be.atlascopco.com>
  • Loading branch information
Eduardo Lezcano committed Apr 20, 2018
1 parent 0605454 commit 0b1ee9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ type DescribeOptions struct {
//FirstParent bool
// Use <Abbrev> digits to display SHA-1s
// By default is 8
//Abbrev int
Abbrev int
// Only output exact matches
//ExactMatch bool
// Consider <Candidates> most recent tags
Expand All @@ -460,4 +460,6 @@ type DescribeOptions struct {
Dirty string
}

func (o *DescribeOptions) Validate() error { return nil }
func (o *DescribeOptions) Validate() error {
if o.Abbrev == 0 { o.Abbrev = 8 }
return nil }
22 changes: 17 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 Expand Up @@ -1290,6 +1301,7 @@ func (r *Repository) Describe(ref *plumbing.Reference, opts *DescribeOptions) (*
tag,
count,
opts.Dirty,
opts.Abbrev,
}, nil

}

0 comments on commit 0b1ee9f

Please sign in to comment.