Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

git: error on empty tag name (#929) #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 11 repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ var (
// ErrFetching is returned when the packfile could not be downloaded
ErrFetching = errors.New("unable to fetch packfile")

// ErrInvalidTagName is returned when the tag name is invalid.
ErrInvalidTagName = errors.New("invalid tag name")

ErrInvalidReference = errors.New("invalid reference, should be a tag or a branch")
ErrRepositoryNotExists = errors.New("repository does not exist")
ErrRepositoryIncomplete = errors.New("repository's commondir path does not exist")
Expand Down Expand Up @@ -724,6 +727,10 @@ func (r *Repository) DeleteBranch(name string) error {
// CreateTag creates a tag. If opts is included, the tag is an annotated tag,
// otherwise a lightweight tag is created.
func (r *Repository) CreateTag(name string, hash plumbing.Hash, opts *CreateTagOptions) (*plumbing.Reference, error) {
if name == "" {
return nil, ErrInvalidTagName
}

rname := plumbing.ReferenceName(path.Join("refs", "tags", name))

_, err := r.Storer.Reference(rname)
Expand Down Expand Up @@ -757,6 +764,10 @@ func (r *Repository) CreateTag(name string, hash plumbing.Hash, opts *CreateTagO
}

func (r *Repository) createTagObject(name string, hash plumbing.Hash, opts *CreateTagOptions) (plumbing.Hash, error) {
if name == "" {
return plumbing.ZeroHash, ErrInvalidTagName
}

if err := opts.Validate(r, hash); err != nil {
return plumbing.ZeroHash, err
}
Expand Down
8 changes: 8 additions & 0 deletions 8 repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3265,6 +3265,14 @@ func (s *RepositorySuite) TestIssue674(c *C) {
c.Check(h.IsZero(), Equals, true)
}

func (s *RepositorySuite) TestEmptyTagName(c *C) {
r, _ := Init(memory.NewStorage(), nil)
_, err := r.CreateTag("", plumbing.ZeroHash, nil)

c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "invalid tag name")
}

func BenchmarkObjects(b *testing.B) {
defer fixtures.Clean()

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.