From 0861069a9744241d2a2749d7b8319e69c8b7db1f Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 21 Feb 2023 18:20:25 +0800 Subject: [PATCH 1/2] return empty url for submodule tree entry --- services/repository/files/tree.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go index f4304ea6306ee..c05c551784ea0 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -85,6 +85,8 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git if entries[e].IsDir() { copy(treeURL[copyPos:], entries[e].ID.String()) tree.Entries[i].URL = string(treeURL) + } else if entries[e].IsSubModule() { + tree.Entries[i].URL = "" } else { copy(blobURL[copyPos:], entries[e].ID.String()) tree.Entries[i].URL = string(blobURL) From 655025e5ef3e322c6d40beca6d7c0f791107b4ce Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 21 Feb 2023 18:49:28 +0800 Subject: [PATCH 2/2] add comment --- services/repository/files/tree.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go index c05c551784ea0..0b1d304845eb2 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -86,6 +86,9 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git copy(treeURL[copyPos:], entries[e].ID.String()) tree.Entries[i].URL = string(treeURL) } else if entries[e].IsSubModule() { + // In Github Rest API Version=2022-11-28, if a tree entry is a submodule, + // its url will be returned as an empty string. + // So the URL will be set to "" here. tree.Entries[i].URL = "" } else { copy(blobURL[copyPos:], entries[e].ID.String())