]> source.dussan.org Git - gitea.git/commitdiff
Return empty url for submodule tree entries (#23043)
authorZettat123 <zettat123@gmail.com>
Tue, 21 Feb 2023 17:31:17 +0000 (01:31 +0800)
committerGitHub <noreply@github.com>
Tue, 21 Feb 2023 17:31:17 +0000 (12:31 -0500)
Close #22614.

Refer to [Github's
API](https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree),
if a tree entry is a submodule, its url will be an empty string.

---------

Co-authored-by: delvh <leon@kske.dev>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
services/repository/files/tree.go

index f4304ea6306ee20b97c4935b4409a8cc871b1b76..0b1d304845eb2a609f637ede9ba1cfab609509ca 100644 (file)
@@ -85,6 +85,11 @@ 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() {
+                       // 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())
                        tree.Entries[i].URL = string(blobURL)