aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorChris Marchesi <chrism@vancluevertech.com>2018-08-18 11:03:33 -0700
committerChris Marchesi <chrism@vancluevertech.com>2018-08-21 17:43:29 -0700
commitb9f5efe3dbee0cd15a553bcc03f7a37f3dcaa676 (patch)
tree3aca261e608995102d63b8898f1e19c11177562e /options.go
parent7b6c1266556f59ac436fada3fa6106d4a84f9b56 (diff)
downloadgo-git-b9f5efe3dbee0cd15a553bcc03f7a37f3dcaa676.tar.gz
git: Add tagging support
This adds a few methods: * CreateTag, which can be used to create both lightweight and annotated tags with a supplied TagObjectOptions struct. PGP signing is possible as well. * Tag, to fetch a single tag ref. As opposed to Tags or TagObjects, this will also fetch the tag object if it exists and return it along with the output. Lightweight tags just return the object as nil. * DeleteTag, to delete a tag. This simply deletes the ref. The object is left orphaned to be GCed later. I'm not 100% sure if DeleteTag is the correct behavior - looking for details on exactly *what* happens to a tag object if you delete the ref and not the tag were sparse, and groking the Git source did not really produce much insight to the untrained eye. This may be something that comes up in review. If deletion of the object is necessary, the in-memory storer may require some updates to allow DeleteLooseObject to be supported. Signed-off-by: Chris Marchesi <chrism@vancluevertech.com>
Diffstat (limited to 'options.go')
-rw-r--r--options.go47
1 files changed, 45 insertions, 2 deletions
diff --git a/options.go b/options.go
index 7b1570f..6b00b0d 100644
--- a/options.go
+++ b/options.go
@@ -348,8 +348,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 +378,48 @@ 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")
+ ErrBadObjectType = errors.New("bad object type for tagging")
+)
+
+// TagObjectOptions describes how a tag object should be created.
+type TagObjectOptions struct {
+ // Tagger defines the signature of the tag creator.
+ Tagger *object.Signature
+ // Message defines the annotation of the tag.
+ Message string
+ // TargetType is the object type of the target. The object specified by
+ // Target must be of this type.
+ TargetType plumbing.ObjectType
+ // 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 *TagObjectOptions) Validate(r *Repository, hash plumbing.Hash) error {
+ if o.Tagger == nil {
+ return ErrMissingTagger
+ }
+
+ if o.Message == "" {
+ return ErrMissingMessage
+ }
+
+ if o.TargetType == plumbing.InvalidObject || o.TargetType == plumbing.AnyObject {
+ return ErrBadObjectType
+ }
+
+ if _, err := r.Object(o.TargetType, hash); err != nil {
+ return err
+ }
+
+ return nil
+}
+
// ListOptions describes how a remote list should be performed.
type ListOptions struct {
// Auth credentials, if required, to use with the remote repository.