]> source.dussan.org Git - gitea.git/commitdiff
Fix NPE on view commit with notes (#15561)
authorzeripath <art27@cantab.net>
Wed, 21 Apr 2021 18:00:27 +0000 (19:00 +0100)
committerGitHub <noreply@github.com>
Wed, 21 Apr 2021 18:00:27 +0000 (19:00 +0100)
Fix #15558

Signed-off-by: Andrew Thornton <art27@cantab.net>
modules/git/notes_nogogit.go

index 613efd2e0e06a288248ff2e52e6af764e2b7cb4b..1379e50853656151ac84f855b637089467f2a8b1 100644 (file)
@@ -8,6 +8,7 @@ package git
 
 import (
        "io/ioutil"
+       "strings"
 )
 
 // GetNote retrieves the git-notes data for a given commit.
@@ -49,7 +50,13 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
        }
        note.Message = d
 
-       lastCommits, err := GetLastCommitForPaths(notes, "", []string{path})
+       treePath := ""
+       if idx := strings.LastIndex(path, "/"); idx > -1 {
+               treePath = path[:idx]
+               path = path[idx+1:]
+       }
+
+       lastCommits, err := GetLastCommitForPaths(notes, treePath, []string{path})
        if err != nil {
                return err
        }