Use new MergeBase method

This commit is contained in:
Lunny Xiao
2025-12-17 20:52:47 -08:00
parent 47f6f1dca9
commit e5fe09301a
4 changed files with 9 additions and 42 deletions
-26
View File
@@ -18,32 +18,6 @@ import (
"code.gitea.io/gitea/modules/git/gitcmd"
)
// GetMergeBase checks and returns merge base of two branches and the reference used as base.
func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, string, error) {
if tmpRemote == "" {
tmpRemote = "origin"
}
if tmpRemote != "origin" {
tmpBaseName := RemotePrefix + tmpRemote + "/tmp_" + base
// Fetch commit into a temporary branch in order to be able to handle commits and tags
_, _, err := gitcmd.NewCommand("fetch", "--no-tags").
AddDynamicArguments(tmpRemote).
AddDashesAndList(base + ":" + tmpBaseName).
WithDir(repo.Path).
RunStdString(repo.Ctx)
if err == nil {
base = tmpBaseName
}
}
stdout, _, err := gitcmd.NewCommand("merge-base").
AddDashesAndList(base, head).
WithDir(repo.Path).
RunStdString(repo.Ctx)
return strings.TrimSpace(stdout), base, err
}
type lineCountWriter struct {
numLines int
}