Skip to content
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

Fix NPE on try to get tag reference via API #18245

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions modules/git/repo_commit_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
if err != nil {
return nil, err
}
tag, err := parseTagData(data)
tag, err := parseTagData(repo, data)
if err != nil {
return nil, err
}
tag.repo = repo

commit, err := tag.Commit()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions modules/git/repo_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
return nil, err
}

tag, err := parseTagData(data)
tag, err := parseTagData(repo, data)
if err != nil {
return nil, err
}

tag.Name = name
tag.ID = tagID
tag.repo = repo
tag.Type = tp

repo.tagCache.Set(tagID.String(), tag)
Expand Down
2 changes: 1 addition & 1 deletion modules/git/repo_tree_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
if err != nil {
return nil, err
}
tag, err := parseTagData(data)
tag, err := parseTagData(repo, data)
if err != nil {
return nil, err
}
6543 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion modules/git/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func (tag *Tag) Commit() (*Commit, error) {
// Parse commit information from the (uncompressed) raw
// data from the commit object.
// \n\n separate headers from message
func parseTagData(data []byte) (*Tag, error) {
func parseTagData(repo *Repository, data []byte) (*Tag, error) {
tag := new(Tag)
tag.repo = repo
tag.Tagger = &Signature{}
// we now have the contents of the commit object. Let's investigate...
nextline := 0
Expand Down
2 changes: 1 addition & 1 deletion modules/git/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ono`), tag: Tag{
}

for _, test := range testData {
tag, err := parseTagData(test.data)
tag, err := parseTagData(nil, test.data)
assert.NoError(t, err)
assert.EqualValues(t, test.tag.ID, tag.ID)
assert.EqualValues(t, test.tag.Object, tag.Object)
Expand Down