diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-09-04 02:48:17 -0300 |
---|---|---|
committer | Lauris BH <lauris.buksis@zzdats.lv> | 2019-09-04 08:48:17 +0300 |
commit | 4cb1bdddc88580d20305415869d4c13827097bd9 (patch) | |
tree | 9adc857ea67e31519d2832ea942906b4b4e37c52 /modules | |
parent | d9545f9ecc7dac49a4daaae8ef378bb755b027f1 (diff) | |
download | gitea-4cb1bdddc88580d20305415869d4c13827097bd9.tar.gz gitea-4cb1bdddc88580d20305415869d4c13827097bd9.zip |
Strict name matching for Repository.GetTagID() (#8074)
* Strict name matching for Repository.GetTagID()
* Perform make swagger-check swagger-validate vendor
* Add test for GetTagID()
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/repo_tag.go | 11 | ||||
-rw-r--r-- | modules/git/repo_tag_test.go | 10 |
2 files changed, 17 insertions, 4 deletions
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index 91a7a0cd50..9e08d00f0d 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -157,11 +157,14 @@ func (repo *Repository) GetTagID(name string) (string, error) { if err != nil { return "", err } - fields := strings.Fields(stdout) - if len(fields) != 2 { - return "", ErrNotExist{ID: name} + // Make sure exact match is used: "v1" != "release/v1" + for _, line := range strings.Split(stdout, "\n") { + fields := strings.Fields(line) + if len(fields) == 2 && fields[1] == "refs/tags/"+name { + return fields[0], nil + } } - return fields[0], nil + return "", ErrNotExist{ID: name} } // GetTag returns a Git tag by given name. diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go index 4f727c6c66..ab9742afc5 100644 --- a/modules/git/repo_tag_test.go +++ b/modules/git/repo_tag_test.go @@ -62,6 +62,16 @@ func TestRepository_GetTag(t *testing.T) { assert.NotEqual(t, aTagID, aTag.Object.String()) assert.EqualValues(t, aTagCommitID, aTag.Object.String()) assert.EqualValues(t, "tag", aTag.Type) + + rTagCommitID := "8006ff9adbf0cb94da7dad9e537e53817f9fa5c0" + rTagName := "release/" + lTagName + bareRepo1.CreateTag(rTagName, rTagCommitID) + rTagID, err := bareRepo1.GetTagID(rTagName) + assert.NoError(t, err) + assert.EqualValues(t, rTagCommitID, rTagID) + oTagID, err := bareRepo1.GetTagID(lTagName) + assert.NoError(t, err) + assert.EqualValues(t, lTagCommitID, oTagID) } func TestRepository_GetAnnotatedTag(t *testing.T) { |