diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2020-06-05 07:02:15 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2020-06-05 07:02:15 +0200 |
commit | 531a81eae684d8cae617d3d9a26923a66eb25d40 (patch) | |
tree | bad8ba6004f59497b00dd4edf098766a375f7beb /options.go | |
parent | 8019144b6534ff58ad234a355e5b143f1c99b45e (diff) | |
download | go-git-531a81eae684d8cae617d3d9a26923a66eb25d40.tar.gz |
CreateTagOptions.Validate: load Tagger from config
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -464,7 +464,8 @@ var ( // CreateTagOptions describes how a tag object should be created. type CreateTagOptions struct { - // Tagger defines the signature of the tag creator. + // Tagger defines the signature of the tag creator. If Tagger is empty the + // Name and Email is read from the config, and time.Now it's used as When. Tagger *object.Signature // Message defines the annotation of the tag. It is canonicalized during // validation into the format expected by git - no leading whitespace and @@ -478,7 +479,9 @@ type CreateTagOptions struct { // Validate validates the fields and sets the default values. func (o *CreateTagOptions) Validate(r *Repository, hash plumbing.Hash) error { if o.Tagger == nil { - return ErrMissingTagger + if err := o.loadConfigTagger(r); err != nil { + return err + } } if o.Message == "" { @@ -491,6 +494,35 @@ func (o *CreateTagOptions) Validate(r *Repository, hash plumbing.Hash) error { return nil } +func (o *CreateTagOptions) loadConfigTagger(r *Repository) error { + cfg, err := r.ConfigScoped(config.SystemScope) + if err != nil { + return err + } + + if o.Tagger == nil && cfg.Author.Email != "" && cfg.Author.Name != "" { + o.Tagger = &object.Signature{ + Name: cfg.Author.Name, + Email: cfg.Author.Email, + When: time.Now(), + } + } + + if o.Tagger == nil && cfg.User.Email != "" && cfg.User.Name != "" { + o.Tagger = &object.Signature{ + Name: cfg.User.Name, + Email: cfg.User.Email, + When: time.Now(), + } + } + + if o.Tagger == nil { + return ErrMissingTagger + } + + return nil +} + // ListOptions describes how a remote list should be performed. type ListOptions struct { // Auth credentials, if required, to use with the remote repository. |