Skip to content

Commit 3c531d3

Browse files
authored
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 <[email protected]> Signed-off-by: Andrew Thornton <[email protected]>
1 parent 1ae2525 commit 3c531d3

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ been added to each release, please refer to the [blog](https://blog.gitea.io).
77
## [1.18.2](https://github.com/go-gitea/gitea/releases/tag/v1.18.2) - 2023-01-19
88

99
* BUGFIXES
10+
* When updating by rebase we need to set the environment for head repo (#22535) (#22536)
1011
* Fix issue not auto-closing when it includes a reference to a branch (#22514) (#22521)
1112
* Fix invalid issue branch reference if not specified in template (#22513) (#22520)
1213
* Fix 500 error viewing pull request when fork has pull requests disabled (#22512) (#22515)

services/pull/merge.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,25 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
584584
headUser = pr.HeadRepo.Owner
585585
}
586586

587-
env = repo_module.FullPushingEnvironment(
588-
headUser,
589-
doer,
590-
pr.BaseRepo,
591-
pr.BaseRepo.Name,
592-
pr.ID,
593-
)
594-
595587
var pushCmd *git.Command
596588
if mergeStyle == repo_model.MergeStyleRebaseUpdate {
597589
// force push the rebase result to head branch
590+
env = repo_module.FullPushingEnvironment(
591+
headUser,
592+
doer,
593+
pr.HeadRepo,
594+
pr.HeadRepo.Name,
595+
pr.ID,
596+
)
598597
pushCmd = git.NewCommand(ctx, "push", "-f", "head_repo").AddDynamicArguments(stagingBranch + ":" + git.BranchPrefix + pr.HeadBranch)
599598
} else {
599+
env = repo_module.FullPushingEnvironment(
600+
headUser,
601+
doer,
602+
pr.BaseRepo,
603+
pr.BaseRepo.Name,
604+
pr.ID,
605+
)
600606
pushCmd = git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch)
601607
}
602608

services/repository/push.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
104104
var pusher *user_model.User
105105

106106
for _, opts := range optsList {
107+
log.Trace("pushUpdates: %-v %s %s %s", repo, opts.OldCommitID, opts.NewCommitID, opts.RefFullName)
108+
107109
if opts.IsNewRef() && opts.IsDelRef() {
108110
return fmt.Errorf("old and new revisions are both %s", git.EmptySHA)
109111
}
@@ -129,7 +131,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
129131
} else { // is new tag
130132
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
131133
if err != nil {
132-
return fmt.Errorf("gitRepo.GetCommit: %w", err)
134+
return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
133135
}
134136

135137
commits := repo_module.NewPushCommits()
@@ -162,7 +164,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
162164

163165
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
164166
if err != nil {
165-
return fmt.Errorf("gitRepo.GetCommit: %w", err)
167+
return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
166168
}
167169

168170
refName := opts.RefName()

0 commit comments

Comments
 (0)