When updating by rebase we need to set the environment for head repo (#22535) (#22536)

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>
This commit is contained in:
zeripath 2023-01-19 22:31:20 +00:00 committed by GitHub
parent 1ae2525922
commit 3c531d3957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View file

@ -7,6 +7,7 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
## [1.18.2](https://github.com/go-gitea/gitea/releases/tag/v1.18.2) - 2023-01-19 ## [1.18.2](https://github.com/go-gitea/gitea/releases/tag/v1.18.2) - 2023-01-19
* BUGFIXES * BUGFIXES
* When updating by rebase we need to set the environment for head repo (#22535) (#22536)
* Fix issue not auto-closing when it includes a reference to a branch (#22514) (#22521) * Fix issue not auto-closing when it includes a reference to a branch (#22514) (#22521)
* Fix invalid issue branch reference if not specified in template (#22513) (#22520) * Fix invalid issue branch reference if not specified in template (#22513) (#22520)
* Fix 500 error viewing pull request when fork has pull requests disabled (#22512) (#22515) * Fix 500 error viewing pull request when fork has pull requests disabled (#22512) (#22515)

View file

@ -584,6 +584,18 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
headUser = pr.HeadRepo.Owner headUser = pr.HeadRepo.Owner
} }
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( env = repo_module.FullPushingEnvironment(
headUser, headUser,
doer, doer,
@ -591,12 +603,6 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
pr.BaseRepo.Name, pr.BaseRepo.Name,
pr.ID, pr.ID,
) )
var pushCmd *git.Command
if mergeStyle == repo_model.MergeStyleRebaseUpdate {
// force push the rebase result to head branch
pushCmd = git.NewCommand(ctx, "push", "-f", "head_repo").AddDynamicArguments(stagingBranch + ":" + git.BranchPrefix + pr.HeadBranch)
} else {
pushCmd = git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch) pushCmd = git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch)
} }

View file

@ -104,6 +104,8 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
var pusher *user_model.User var pusher *user_model.User
for _, opts := range optsList { for _, opts := range optsList {
log.Trace("pushUpdates: %-v %s %s %s", repo, opts.OldCommitID, opts.NewCommitID, opts.RefFullName)
if opts.IsNewRef() && opts.IsDelRef() { if opts.IsNewRef() && opts.IsDelRef() {
return fmt.Errorf("old and new revisions are both %s", git.EmptySHA) 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 } else { // is new tag
newCommit, err := gitRepo.GetCommit(opts.NewCommitID) newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil { 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() commits := repo_module.NewPushCommits()
@ -162,7 +164,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
newCommit, err := gitRepo.GetCommit(opts.NewCommitID) newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil { 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() refName := opts.RefName()