From 4160bdb6eb89b2853808ab6b7a94b7c1a49396a0 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 9 Jan 2025 11:10:53 -0300 Subject: [PATCH] fix(blogo,gitea): return repository as a root directory for "." calls --- blogo/gitea/fs.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/blogo/gitea/fs.go b/blogo/gitea/fs.go index 51993de..6fe38b3 100644 --- a/blogo/gitea/fs.go +++ b/blogo/gitea/fs.go @@ -77,6 +77,34 @@ func (fsys *repositoryFS) Open(name string) (fs.File, error) { return nil, &fs.PathError{Op: "open", Path: name, Err: err} } + // If the function is being called to open the root directory, return the + // repository as a root directory. We are returning it here since we can get + // a SHA of the past returned files. + if name == "." { + sha := "" + if len(list) > 0 { + sha = list[0].LastCommitSha + } + + return &repositoryDirFile{repositoryFile{ + contentsResponse: contentsResponse{ + Name: fsys.repo, + Path: ".", + SHA: sha, + LastCommitSha: sha, + Type: "dir", + }, + + owner: fsys.owner, + repo: fsys.repo, + ref: fsys.ref, + + client: fsys.client, + + contents: nil, + }, 0}, nil + } + i := slices.IndexFunc(list, func(i *contentsResponse) bool { return i.Path == name })