From 2f89a0454a10c05e0100e4f1759cc2a6395cdf03 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 24 Jul 2025 16:53:19 -0700 Subject: [PATCH] Fix bug --- routers/api/v1/repo/pull.go | 10 +++++----- routers/web/repo/compare.go | 2 +- routers/web/repo/pull.go | 6 +++--- services/pull/compare.go | 8 ++++---- services/pull/pull.go | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 74f01452e6c..ff6ddbce2d4 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1201,7 +1201,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) return nil, nil } - compareInfo, err := pull_service.GetCompareInfo(ctx, baseRepo, headGitRepo, baseRef.ShortName(), headRef.ShortName(), false, false) + compareInfo, err := pull_service.GetCompareInfo(ctx, baseRepo, headRepo, headGitRepo, baseRef.ShortName(), headRef.ShortName(), false, false) if err != nil { ctx.APIErrorInternal(err) return nil, nil @@ -1461,9 +1461,9 @@ func GetPullRequestCommits(ctx *context.APIContext) { defer closer.Close() if pr.HasMerged { - prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, baseGitRepo, pr.MergeBase, pr.GetGitHeadRefName(), false, false) + prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, pr.BaseRepo, baseGitRepo, pr.MergeBase, pr.GetGitHeadRefName(), false, false) } else { - prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, baseGitRepo, pr.BaseBranch, pr.GetGitHeadRefName(), false, false) + prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, pr.BaseRepo, baseGitRepo, pr.BaseBranch, pr.GetGitHeadRefName(), false, false) } if err != nil { ctx.APIErrorInternal(err) @@ -1584,9 +1584,9 @@ func GetPullRequestFiles(ctx *context.APIContext) { var prInfo *pull_service.CompareInfo if pr.HasMerged { - prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, baseGitRepo, pr.MergeBase, pr.GetGitHeadRefName(), true, false) + prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, pr.BaseRepo, baseGitRepo, pr.MergeBase, pr.GetGitHeadRefName(), true, false) } else { - prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, baseGitRepo, pr.BaseBranch, pr.GetGitHeadRefName(), true, false) + prInfo, err = pull_service.GetCompareInfo(ctx, pr.BaseRepo, pr.BaseRepo, baseGitRepo, pr.BaseBranch, pr.GetGitHeadRefName(), true, false) } if err != nil { ctx.APIErrorInternal(err) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 6980a6e0dc2..8f36b1dca36 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -551,7 +551,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo { headBranchRef = git.TagPrefix + ci.HeadBranch } - ci.CompareInfo, err = pull_service.GetCompareInfo(ctx, baseRepo, ci.HeadGitRepo, baseBranchRef, headBranchRef, ci.DirectComparison, fileOnly) + ci.CompareInfo, err = pull_service.GetCompareInfo(ctx, baseRepo, ci.HeadRepo, ci.HeadGitRepo, baseBranchRef, headBranchRef, ci.DirectComparison, fileOnly) if err != nil { ctx.ServerError("GetCompareInfo", err) return nil diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 5af33b40bb4..1d18f0b30d8 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -273,7 +273,7 @@ func prepareMergedViewPullInfo(ctx *context.Context, issue *issues_model.Issue) baseCommit := GetMergedBaseCommitID(ctx, issue) - compareInfo, err := pull_service.GetCompareInfo(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, + compareInfo, err := pull_service.GetCompareInfo(ctx, ctx.Repo.Repository, ctx.Repo.Repository, ctx.Repo.GitRepo, baseCommit, pull.GetGitHeadRefName(), false, false) if err != nil { if strings.Contains(err.Error(), "fatal: Not a valid object name") || strings.Contains(err.Error(), "unknown revision or path not in the working tree") { @@ -373,7 +373,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses) } - compareInfo, err := pull_service.GetCompareInfo(ctx, pull.BaseRepo, baseGitRepo, + compareInfo, err := pull_service.GetCompareInfo(ctx, pull.BaseRepo, pull.BaseRepo, baseGitRepo, pull.MergeBase, pull.GetGitHeadRefName(), false, false) if err != nil { if strings.Contains(err.Error(), "fatal: Not a valid object name") { @@ -521,7 +521,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_ } } - compareInfo, err := pull_service.GetCompareInfo(ctx, pull.BaseRepo, baseGitRepo, + compareInfo, err := pull_service.GetCompareInfo(ctx, pull.BaseRepo, pull.BaseRepo, baseGitRepo, git.BranchPrefix+pull.BaseBranch, pull.GetGitHeadRefName(), false, false) if err != nil { if strings.Contains(err.Error(), "fatal: Not a valid object name") { diff --git a/services/pull/compare.go b/services/pull/compare.go index a687ee572f2..f8b5ba20a88 100644 --- a/services/pull/compare.go +++ b/services/pull/compare.go @@ -25,21 +25,21 @@ type CompareInfo struct { } // GetCompareInfo generates and returns compare information between base and head branches of repositories. -func GetCompareInfo(ctx context.Context, baseRepo *repo_model.Repository, headGitRepo *git.Repository, baseBranch, headBranch string, directComparison, fileOnly bool) (_ *CompareInfo, err error) { +func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Repository, headGitRepo *git.Repository, baseBranch, headBranch string, directComparison, fileOnly bool) (_ *CompareInfo, err error) { var ( remoteBranch string tmpRemote string ) // We don't need a temporary remote for same repository. - if baseRepo.RepoPath() != headGitRepo.Path { + if headGitRepo.Path != baseRepo.RepoPath() { // Add a temporary remote tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10) - if err = gitrepo.AddGitRemote(ctx, baseRepo, tmpRemote, headGitRepo.Path); err != nil { + if err = gitrepo.AddGitRemote(ctx, headRepo, tmpRemote, baseRepo.RepoPath()); err != nil { return nil, fmt.Errorf("AddRemote: %w", err) } defer func() { - if err := gitrepo.RemoveGitRemote(ctx, baseRepo, tmpRemote); err != nil { + if err := gitrepo.RemoveGitRemote(ctx, headRepo, tmpRemote); err != nil { logger.Error("GetPullRequestInfo: RemoveGitRemote: %v", err) } }() diff --git a/services/pull/pull.go b/services/pull/pull.go index f5de728e3d5..4df46e4c380 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -142,7 +142,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error { return err } - compareInfo, err := GetCompareInfo(ctx, pr.BaseRepo, baseGitRepo, + compareInfo, err := GetCompareInfo(ctx, pr.BaseRepo, pr.BaseRepo, baseGitRepo, git.BranchPrefix+pr.BaseBranch, pr.GetGitHeadRefName(), false, false) if err != nil { return err @@ -1077,7 +1077,7 @@ func GetPullCommits(ctx *gitea_context.Context, issue *issues_model.Issue) ([]Co if pull.HasMerged { baseBranch = pull.MergeBase } - prInfo, err := GetCompareInfo(ctx, pull.BaseRepo, baseGitRepo, baseBranch, pull.GetGitHeadRefName(), true, false) + prInfo, err := GetCompareInfo(ctx, pull.BaseRepo, pull.BaseRepo, baseGitRepo, baseBranch, pull.GetGitHeadRefName(), true, false) if err != nil { return nil, "", err }