mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-27 04:06:10 +01:00
e019eb33a2
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 commitedd219d8e9
) (cherry picked from commit2c0105ef17
) (cherry picked from commit3975a9f3aa
) (cherry picked from commitdee4a18423
) (cherry picked from commit60aee6370f
)
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// 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)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !entry.IsDir() && !entry.IsSubModule() {
|
|
return entry.Blob(), nil
|
|
}
|
|
|
|
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}
|
|
}
|