diff options
author | zeripath <art27@cantab.net> | 2023-01-19 22:31:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 17:31:20 -0500 |
commit | 3c531d39572283a62e3b5b4c4b9b8ba67711bdaf (patch) | |
tree | 2778d29c9abefa9d0515f9682cfa6ba6a6ae5587 /services | |
parent | 1ae2525922b7c2b93e44819ab3732137b24983cb (diff) | |
download | gitea-3c531d39572283a62e3b5b4c4b9b8ba67711bdaf.tar.gz gitea-3c531d39572283a62e3b5b4c4b9b8ba67711bdaf.zip |
When updating by rebase we need to set the environment for head repo (#22535) (#22536)v1.18.2
Backport #22535
The update by rebase code reuses the merge code but shortcircuits and
pushes back up to the head. However, it doesn't set the correct pushing
environment - and just uses the same environment as the base repo. This
leads to the push update failing and thence the PR becomes out-of-sync
with the head.
This PR fixes this and adjusts the trace logging elsewhere to help make
this clearer.
Fix #18802
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services')
-rw-r--r-- | services/pull/merge.go | 22 | ||||
-rw-r--r-- | services/repository/push.go | 6 |
2 files changed, 18 insertions, 10 deletions
diff --git a/services/pull/merge.go b/services/pull/merge.go index 74f3b17c66..ddfac5a219 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -584,19 +584,25 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode headUser = pr.HeadRepo.Owner } - env = repo_module.FullPushingEnvironment( - headUser, - doer, - pr.BaseRepo, - pr.BaseRepo.Name, - pr.ID, - ) - var pushCmd *git.Command if mergeStyle == repo_model.MergeStyleRebaseUpdate { // force push the rebase result to head branch + env = repo_module.FullPushingEnvironment( + headUser, + doer, + pr.HeadRepo, + pr.HeadRepo.Name, + pr.ID, + ) pushCmd = git.NewCommand(ctx, "push", "-f", "head_repo").AddDynamicArguments(stagingBranch + ":" + git.BranchPrefix + pr.HeadBranch) } else { + env = repo_module.FullPushingEnvironment( + headUser, + doer, + pr.BaseRepo, + pr.BaseRepo.Name, + pr.ID, + ) pushCmd = git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch) } diff --git a/services/repository/push.go b/services/repository/push.go index 3a7205d18b..dec5222432 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -104,6 +104,8 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { var pusher *user_model.User for _, opts := range optsList { + log.Trace("pushUpdates: %-v %s %s %s", repo, opts.OldCommitID, opts.NewCommitID, opts.RefFullName) + if opts.IsNewRef() && opts.IsDelRef() { return fmt.Errorf("old and new revisions are both %s", git.EmptySHA) } @@ -129,7 +131,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } else { // is new tag newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { - return fmt.Errorf("gitRepo.GetCommit: %w", err) + return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err) } commits := repo_module.NewPushCommits() @@ -162,7 +164,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { newCommit, err := gitRepo.GetCommit(opts.NewCommitID) if err != nil { - return fmt.Errorf("gitRepo.GetCommit: %w", err) + return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err) } refName := opts.RefName() |