Skip to content

Commit

Permalink
tag: use name not refspec
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Mar 8, 2020
1 parent 86b0130 commit 8d75155
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion repo_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (r *Repository) NewHook(dir string, name HookName) *Hook {
}

// Hook returns a Git hook by given name in the repository. Giving empty directory
// will use the default directory.It returns an os.ErrNotExist if both active and
// will use the default directory. It returns an os.ErrNotExist if both active and
// sample hook do not exist.
func (r *Repository) Hook(dir string, name HookName) (*Hook, error) {
if dir == "" {
Expand Down
9 changes: 5 additions & 4 deletions repo_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ type TagOptions struct {
Timeout time.Duration
}

// Tag returns a Git tag by given refspec, e.g. "refs/tags/v1.0.0".
func (r *Repository) Tag(refspec string, opts ...TagOptions) (*Tag, error) {
// Tag returns a Git tag by given name, e.g. "v1.0.0".
func (r *Repository) Tag(name string, opts ...TagOptions) (*Tag, error) {
var opt TagOptions
if len(opts) > 0 {
opt = opts[0]
}

refsepc := RefsTags + name
refs, err := r.ShowRef(ShowRefOptions{
Tags: true,
Patterns: []string{refspec},
Patterns: []string{refsepc},
Timeout: opt.Timeout,
})
if err != nil {
Expand All @@ -134,7 +135,7 @@ func (r *Repository) Tag(refspec string, opts ...TagOptions) (*Tag, error) {
if err != nil {
return nil, err
}
tag.refspec = refspec
tag.refspec = refsepc
return tag, nil
}

Expand Down
16 changes: 8 additions & 8 deletions repo_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ import (

func TestRepository_Tag(t *testing.T) {
tests := []struct {
refspec string
opt TagOptions
expTag *Tag
name string
opt TagOptions
expTag *Tag
}{
{
refspec: "v1.0.0",
name: "v1.0.0",
expTag: &Tag{
typ: ObjectCommit,
id: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"),
commitID: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"),
refspec: "v1.0.0",
refspec: "refs/tags/v1.0.0",
},
}, {
refspec: "v1.1.0",
name: "v1.1.0",
expTag: &Tag{
typ: ObjectTag,
id: MustIDFromString("b39c8508bbc4b00ad2e24d358012ea123bcafd8d"),
commitID: MustIDFromString("0eedd79eba4394bbef888c804e899731644367fe"),
refspec: "v1.1.0",
refspec: "refs/tags/v1.1.0",
},
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
tag, err := testrepo.Tag(test.refspec, test.opt)
tag, err := testrepo.Tag(test.name, test.opt)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestTag(t *testing.T) {
assert.Equal(t, ObjectTag, tag.Type())
assert.Equal(t, "b39c8508bbc4b00ad2e24d358012ea123bcafd8d", tag.ID().String())
assert.Equal(t, "0eedd79eba4394bbef888c804e899731644367fe", tag.CommitID().String())
assert.Equal(t, "v1.1.0", tag.Refspec())
assert.Equal(t, "refs/tags/v1.1.0", tag.Refspec())

t.Run("Tagger", func(t *testing.T) {
assert.Equal(t, "Joe Chen", tag.Tagger().Name)
Expand Down

0 comments on commit 8d75155

Please sign in to comment.