diff --git a/internal/source/gitea/gitea.go b/internal/source/gitea/gitea.go index c3c513c..1fb1dac 100644 --- a/internal/source/gitea/gitea.go +++ b/internal/source/gitea/gitea.go @@ -467,9 +467,16 @@ func (g Gitea) fetchCheckout(ctx context.Context, repo *git.Repository, branch, var headRef *plumbing.Reference + targetBranch, err := repo.Branch(branch) + if err != nil { + g.logger.Error(ctx, "cant get repo branch", err) + return nil, nil, err + } + g.logger.Info(ctx, "targetBranch: ", targetBranch) + branches, err := repo.Branches() if err != nil { - g.logger.Error(ctx, "cant get repo branches", err) + g.logger.Error(ctx, "cant get repo branch", err) return nil, nil, err } @@ -493,12 +500,26 @@ func (g Gitea) fetchCheckout(ctx context.Context, repo *git.Repository, branch, g.logger.Info(ctx, "repo head "+headRef.String()) + rev, err := repo.ResolveRevision(plumbing.Revision(fmt.Sprintf("remotes/%s/%s", targetBranch.Remote, headRef.Name().Short()))) + if err != nil { + g.logger.Error(ctx, "resolve revision error: ", err) + return nil, nil, err + } + wtree, err := repo.Worktree() if err != nil { g.logger.Error(ctx, "failed to get worktree", err) return nil, nil, err } + if err = wtree.Reset(&git.ResetOptions{ + Commit: *rev, + Mode: git.HardReset, + }); err != nil { + g.logger.Error(ctx, "reset work_tree error: ", err) + return nil, nil, err + } + g.pulls, err = g.GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) if err != nil && err != ErrPRNotExist { g.logger.Error(ctx, "GetPulls error", err)