From add74fb368b4b6a5deee91e052240c0956d7dc5b Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 29 Jun 2021 21:12:43 +0100 Subject: [PATCH] Fix panic in recursive cache (#16298) There is a bug with last commit cache recursive cache where the last commit information that refers to the current tree itself will cause a panic due to its path ("") not being included in the expected tree entry paths. This PR fixes this by skipping the missing entry. Fix #16290 Signed-off-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick --- modules/git/last_commit_cache_nogogit.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/git/last_commit_cache_nogogit.go b/modules/git/last_commit_cache_nogogit.go index ff9f9ff1cf..faf6e23fa8 100644 --- a/modules/git/last_commit_cache_nogogit.go +++ b/modules/git/last_commit_cache_nogogit.go @@ -94,7 +94,8 @@ func (c *LastCommitCache) recursiveCache(ctx context.Context, commit *Commit, tr if err := c.Put(commit.ID.String(), path.Join(treePath, entry), entryCommit.ID.String()); err != nil { return err } - if entryMap[entry].IsDir() { + // entryMap won't contain "" therefore skip this. + if treeEntry := entryMap[entry]; treeEntry != nil && treeEntry.IsDir() { subTree, err := tree.SubTree(entry) if err != nil { return err