Use new MergeBase method

This commit is contained in:
Lunny Xiao committed 2025-12-17 20:52:47 -08:00
1 parent 47f6f1dca9
commit e5fe09301a
4 files changed
+9 -42

No files matched your search

+7 -7
View File
@@ -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)
}