summaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorGergely Nagy <forgejo@gergo.csillger.hu>2024-01-05 10:44:33 +0100
committerEarl Warren <contact@earl-warren.org>2024-02-05 16:09:42 +0100
commite019eb33a2f9289dc41f070f13c5025f2a492bbf (patch)
treef000b55009aab2f06c26184eee07de12744c46f5 /modules/git
parent[GITEA] Check for Commit in opengraph (diff)
downloadforgejo-e019eb33a2f9289dc41f070f13c5025f2a492bbf.tar.xz
forgejo-e019eb33a2f9289dc41f070f13c5025f2a492bbf.zip
[GITEA] Find README.md for user profiles case insensitively
When trying to find a `README.md` in a `.profile` repo, do so case insensitively. This change does not make it possible to render readmes in formats other than Markdown, it just removes the hard-coded "README.md". Also adds a few tests to make sure the change works. Fixes #1494. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu> (cherry picked from commit edd219d8e9d69becb9814ab0a8359555e80fcd4f) (cherry picked from commit 2c0105ef17b9673e6892a66aa689af7c5c87b8a1) (cherry picked from commit 3975a9f3aaf8ed3ceb5788abc325dbe8e89225d3) (cherry picked from commit dee4a18423151ac7f22221e6fce12d863921c200) (cherry picked from commit 60aee6370fb15b12fffc6f29582dd4a235f87d94)
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/tree_blob.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/git/tree_blob.go b/modules/git/tree_blob.go
index 31d9f3d73b..e60c1f915b 100644
--- a/modules/git/tree_blob.go
+++ b/modules/git/tree_blob.go
@@ -1,9 +1,12 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
// SPDX-License-Identifier: MIT
package git
+import "strings"
+
// GetBlobByPath get the blob object according the path
func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) {
entry, err := t.GetTreeEntryByPath(relpath)
@@ -17,3 +20,21 @@ func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) {
return nil, ErrNotExist{"", relpath}
}
+
+// GetBlobByFoldedPath returns the blob object at relpath, regardless of the
+// case of relpath. If there are multiple files with the same case-insensitive
+// name, the first one found will be returned.
+func (t *Tree) GetBlobByFoldedPath(relpath string) (*Blob, error) {
+ entries, err := t.ListEntries()
+ if err != nil {
+ return nil, err
+ }
+
+ for _, entry := range entries {
+ if strings.EqualFold(entry.Name(), relpath) {
+ return t.GetBlobByPath(entry.Name())
+ }
+ }
+
+ return nil, ErrNotExist{"", relpath}
+}