mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-23 18:54:39 +02:00
Use new MergeBase method
This commit is contained in:
4 files changed
+9
-42
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -12,23 +12,23 @@ import (
|
||||
)
|
||||
|
||||
// MergeBase checks and returns merge base of two commits.
|
||||
func MergeBase(ctx context.Context, repo Repository, commit1, commit2 string) (string, error) {
|
||||
func MergeBase(ctx context.Context, repo Repository, baseCommitID, headCommitID string) (string, error) {
|
||||
mergeBase, err := RunCmdString(ctx, repo, gitcmd.NewCommand("merge-base").
|
||||
AddDashesAndList(commit1, commit2))
|
||||
AddDashesAndList(baseCommitID, headCommitID))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("get merge-base of %s and %s failed: %w", commit1, commit2, err)
|
||||
return "", fmt.Errorf("get merge-base of %s and %s failed: %w", baseCommitID, headCommitID, err)
|
||||
}
|
||||
return strings.TrimSpace(mergeBase), nil
|
||||
}
|
||||
|
||||
// MergeBaseFromRemote checks and returns merge base of two commits from different repositories.
|
||||
func MergeBaseFromRemote(ctx context.Context, repo, remoteRepo Repository, commit1, commit2 string) (string, error) {
|
||||
func MergeBaseFromRemote(ctx context.Context, baseRepo, headRepo Repository, baseCommitID, headCommitID string) (string, error) {
|
||||
// fetch head commit id into the current repository if the repositories are different
|
||||
if repo.RelativePath() != remoteRepo.RelativePath() {
|
||||
if err := FetchRemoteCommit(ctx, repo, remoteRepo, commit2); err != nil {
|
||||
if baseRepo.RelativePath() != headRepo.RelativePath() {
|
||||
if err := FetchRemoteCommit(ctx, baseRepo, headRepo, headCommitID); err != nil {
|
||||
return "", fmt.Errorf("FetchRemoteCommit: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return MergeBase(ctx, repo, commit1, commit2)
|
||||
return MergeBase(ctx, baseRepo, baseCommitID, headCommitID)
|
||||
}
|
||||
Reference in new issue
Block a user