Skip to content

Commit 567e117

Browse files
richmahnzeripath
authored andcommitted
Fixes #7238 - Annotated tag commit ID incorrect (#7321)
* Fixes #7238 - Annotated tag commit ID incorrect * Fixes #7238 - Annotated tag commit ID incorrect
1 parent 7bd0dc4 commit 567e117

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

modules/git/repo_tag.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ func (repo *Repository) GetTagNameBySHA(sha string) (string, error) {
141141
fields := strings.Fields(tagRef)
142142
if strings.HasPrefix(fields[0], sha) && strings.HasPrefix(fields[1], TagPrefix) {
143143
name := fields[1][len(TagPrefix):]
144-
// annotated tags show up twice, their name for commit ID is suffixed with ^{}
145-
name = strings.TrimSuffix(name, "^{}")
146-
return name, nil
144+
// annotated tags show up twice, we should only return if is not the ^{} ref
145+
if !strings.HasSuffix(name, "^{}") {
146+
return name, nil
147+
}
147148
}
148149
}
149150
}

routers/api/v1/convert/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func ToCommitUser(sig *git.Signature) *api.CommitUser {
281281
// ToCommitMeta convert a git.Tag to an api.CommitMeta
282282
func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
283283
return &api.CommitMeta{
284-
SHA: tag.ID.String(),
284+
SHA: tag.Object.String(),
285285
// TODO: Add the /commits API endpoint and use it here (https://developer.github.com/v3/repos/commits/#get-a-single-commit)
286286
URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
287287
}

0 commit comments

Comments
 (0)