diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-09-10 13:04:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-10 13:04:42 +0200 |
commit | 38060c9c17a8485c03873d06b465b65dbe6bd325 (patch) | |
tree | f0273e3453020498defff396e3d62e9f33436468 /options.go | |
parent | a2d62f58ea626bb9f41de6431f6f18ca92cf78a0 (diff) | |
parent | 9ce4eeab99708a2ac35124585103f9e4a04126df (diff) | |
download | go-git-38060c9c17a8485c03873d06b465b65dbe6bd325.tar.gz |
Merge pull request #928 from vancluever/f-add-tagging-support
git: Add tagging support
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 41 |
1 files changed, 39 insertions, 2 deletions
@@ -3,6 +3,7 @@ package git import ( "errors" "regexp" + "strings" "golang.org/x/crypto/openpgp" "gopkg.in/src-d/go-git.v4/config" @@ -348,8 +349,9 @@ type CommitOptions struct { // Parents are the parents commits for the new commit, by default when // len(Parents) is zero, the hash of HEAD reference is used. Parents []plumbing.Hash - // A key to sign the commit with. A nil value here means the commit will not - // be signed. The private key must be present and already decrypted. + // SignKey denotes a key to sign the commit with. A nil value here means the + // commit will not be signed. The private key must be present and already + // decrypted. SignKey *openpgp.Entity } @@ -377,6 +379,41 @@ func (o *CommitOptions) Validate(r *Repository) error { return nil } +var ( + ErrMissingName = errors.New("name field is required") + ErrMissingTagger = errors.New("tagger field is required") + ErrMissingMessage = errors.New("message field is required") +) + +// CreateTagOptions describes how a tag object should be created. +type CreateTagOptions struct { + // Tagger defines the signature of the tag creator. + 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 + // ending in a newline. + Message string + // SignKey denotes a key to sign the tag with. A nil value here means the tag + // will not be signed. The private key must be present and already decrypted. + SignKey *openpgp.Entity +} + +// 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 o.Message == "" { + return ErrMissingMessage + } + + // Canonicalize the message into the expected message format. + o.Message = strings.TrimSpace(o.Message) + "\n" + + return nil +} + // ListOptions describes how a remote list should be performed. type ListOptions struct { // Auth credentials, if required, to use with the remote repository. |