From 248b67af6f81f2f2e093260482a8c05306613e33 Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 21 Apr 2021 20:11:43 +0100 Subject: [PATCH] Fix NPE on view commit with notes (#15561) (#15573) Backport #15561 Fix #15558 Signed-off-by: Andrew Thornton --- modules/git/notes_nogogit.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/git/notes_nogogit.go b/modules/git/notes_nogogit.go index 613efd2e0e..1379e50853 100644 --- a/modules/git/notes_nogogit.go +++ b/modules/git/notes_nogogit.go @@ -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 }