diff options
-rw-r--r-- | options.go | 12 | ||||
-rw-r--r-- | repository.go | 7 | ||||
-rw-r--r-- | repository_test.go | 52 |
3 files changed, 30 insertions, 41 deletions
@@ -383,7 +383,6 @@ 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. @@ -394,9 +393,6 @@ type TagObjectOptions struct { // validation into the format expected by git - no leading whitespace and // ending in a newline. 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 @@ -415,14 +411,6 @@ func (o *TagObjectOptions) Validate(r *Repository, hash plumbing.Hash) error { // Canonicalize the message into the expected message format. o.Message = strings.TrimSpace(o.Message) + "\n" - if o.TargetType == plumbing.InvalidObject || o.TargetType == plumbing.AnyObject { - return ErrBadObjectType - } - - if _, err := r.Object(o.TargetType, hash); err != nil { - return err - } - return nil } diff --git a/repository.go b/repository.go index ab14eba..6da15a1 100644 --- a/repository.go +++ b/repository.go @@ -532,11 +532,16 @@ func (r *Repository) createTagObject(name string, hash plumbing.Hash, opts *TagO return plumbing.ZeroHash, err } + rawobj, err := object.GetObject(r.Storer, hash) + if err != nil { + return plumbing.ZeroHash, err + } + tag := &object.Tag{ Name: name, Tagger: *opts.Tagger, Message: opts.Message, - TargetType: opts.TargetType, + TargetType: rawobj.Type(), Target: hash, } diff --git a/repository_test.go b/repository_test.go index fd80152..795ee55 100644 --- a/repository_test.go +++ b/repository_test.go @@ -1333,9 +1333,8 @@ func (s *RepositorySuite) TestCreateTagAnnotated(c *C) { expectedHash := h.Hash() ref, err := r.CreateTag("foobar", expectedHash, &TagObjectOptions{ - Tagger: defaultSignature(), - Message: "foo bar baz qux", - TargetType: plumbing.CommitObject, + Tagger: defaultSignature(), + Message: "foo bar baz qux", }) c.Assert(err, IsNil) @@ -1364,32 +1363,32 @@ func (s *RepositorySuite) TestCreateTagAnnotatedBadOpts(c *C) { expectedHash := h.Hash() ref, err := r.CreateTag("foobar", expectedHash, &TagObjectOptions{ - Message: "foo bar baz qux", - TargetType: plumbing.CommitObject, + Message: "foo bar baz qux", }) c.Assert(ref, IsNil) c.Assert(err, Equals, ErrMissingTagger) ref, err = r.CreateTag("foobar", expectedHash, &TagObjectOptions{ - Tagger: defaultSignature(), - TargetType: plumbing.CommitObject, + Tagger: defaultSignature(), }) c.Assert(ref, IsNil) c.Assert(err, Equals, ErrMissingMessage) +} - ref, err = r.CreateTag("foobar", expectedHash, &TagObjectOptions{ +func (s *RepositorySuite) TestCreateTagAnnotatedBadHash(c *C) { + url := s.GetLocalRepositoryURL( + fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(), + ) + + r, _ := Init(memory.NewStorage(), nil) + err := r.clone(context.Background(), &CloneOptions{URL: url}) + c.Assert(err, IsNil) + + ref, err := r.CreateTag("foobar", plumbing.ZeroHash, &TagObjectOptions{ Tagger: defaultSignature(), Message: "foo bar baz qux", }) c.Assert(ref, IsNil) - c.Assert(err, Equals, ErrBadObjectType) - - ref, err = r.CreateTag("foobar", expectedHash, &TagObjectOptions{ - Tagger: defaultSignature(), - Message: "foo bar baz qux", - TargetType: plumbing.TagObject, - }) - c.Assert(ref, IsNil) c.Assert(err, Equals, plumbing.ErrObjectNotFound) } @@ -1407,10 +1406,9 @@ func (s *RepositorySuite) TestCreateTagSigned(c *C) { key := commitSignKey(c, true) _, err = r.CreateTag("foobar", h.Hash(), &TagObjectOptions{ - Tagger: defaultSignature(), - Message: "foo bar baz qux", - TargetType: plumbing.CommitObject, - SignKey: key, + Tagger: defaultSignature(), + Message: "foo bar baz qux", + SignKey: key, }) c.Assert(err, IsNil) @@ -1447,10 +1445,9 @@ func (s *RepositorySuite) TestCreateTagSignedBadKey(c *C) { key := commitSignKey(c, false) _, err = r.CreateTag("foobar", h.Hash(), &TagObjectOptions{ - Tagger: defaultSignature(), - Message: "foo bar baz qux", - TargetType: plumbing.CommitObject, - SignKey: key, + Tagger: defaultSignature(), + Message: "foo bar baz qux", + SignKey: key, }) c.Assert(err, Equals, openpgperr.InvalidArgumentError("signing key is encrypted")) } @@ -1469,10 +1466,9 @@ func (s *RepositorySuite) TestCreateTagCanonicalize(c *C) { key := commitSignKey(c, true) _, err = r.CreateTag("foobar", h.Hash(), &TagObjectOptions{ - Tagger: defaultSignature(), - Message: "\n\nfoo bar baz qux\n\nsome message here", - TargetType: plumbing.CommitObject, - SignKey: key, + Tagger: defaultSignature(), + Message: "\n\nfoo bar baz qux\n\nsome message here", + SignKey: key, }) c.Assert(err, IsNil) |