From 96e050ec63039b7c10f18aeaf8d3d766ad4c95e4 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 5 Jan 2025 23:17:40 -0800 Subject: [PATCH] Fix bugs --- services/repository/files/tree.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go index d6cfdad8da..b1f63790f1 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -425,10 +425,15 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa } dir = treePath if lastDirEntry.IsRegular() { - dir = path.Dir(treePath) - lastDirEntry, err = commit.GetTreeEntryByPath(dir) - if err != nil { - return nil, err + // path.Dir cannot correctly handle .xxx file + dir, _ = path.Split(treePath) + if dir == "" { + lastDirEntry = rootEntry + } else { + lastDirEntry, err = commit.GetTreeEntryByPath(dir) + if err != nil { + return nil, err + } } } } @@ -448,6 +453,7 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa } } + sortTreeEntries(treeList) if dir == "" || parentEntry == nil { return treeList, nil } @@ -475,7 +481,6 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa Path: path.Join(dir, entry.Name()), }) } - sortTreeEntries(treeList) sortTreeEntries(parentEntry.Children) return treeList, nil }