Files
gitea/modules/git/fastimport.go
Shudhanshu Singh c0f4e5583e feat(repo): prioritize well-known READMEs and optimize discovery (#38532)
This PR adjusts the repository README discovery logic to mirror GitHub's
priority order, while retaining support for Gitea's specific `.gitea/`
directory.

Previously, Gitea would prioritize a `README.md` at the root of the
repository over any READMEs in `.gitea/` or `.github/`. With this
change, well-known subdirectories are evaluated first when viewing the
repository root.

**New Priority Order:**
1. `.gitea/README.md`
2. `.github/README.md`
3. `/README.md` (root directory)
4. `docs/README.md`

This allows repository maintainers to use `.github/README.md` (or
`.gitea/README.md`) as the repository homepage without having to remove
or rename generic root `/README.md` files required by package managers
(like NPM, Crates.io, Docker, etc.).

---------

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-07-21 11:44:25 +08:00

43 lines
1.1 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"bytes"
"context"
"fmt"
"gitea.dev/modules/git/gitcmd"
)
type FastImportFile struct {
Mode EntryMode
Path string
Content string
}
type FastImportCommit struct {
Ref string
Message string
Files []FastImportFile
}
// ForceFastImport is for mainly for testing purpose
func ForceFastImport(ctx context.Context, repo RepositoryFacade, commits []FastImportCommit) error {
var buf bytes.Buffer
for i, c := range commits {
_, _ = fmt.Fprintf(&buf, "reset %s\n", c.Ref)
_, _ = fmt.Fprintf(&buf, "commit %s\nmark :%d\ncommitter Gitea <gitea@example.com> 1500000000 +0000\n", c.Ref, i+1)
_, _ = fmt.Fprintf(&buf, "data %d\n%s\n", len(c.Message), c.Message)
for _, f := range c.Files {
_, _ = fmt.Fprintf(&buf, "M %s inline %s\ndata %d\n%s\n", f.Mode.String(), f.Path, len(f.Content), f.Content)
}
}
buf.WriteString("done\n")
_, _, err := gitcmd.NewCommand("fast-import").AddArguments("--force", "--done").
WithRepo(repo).WithStdinBytes(buf.Bytes()).
RunStdString(ctx)
return err
}