Skip to content

Commit 4199d28

Browse files
zeripathjolheiser
andauthored
When updating by rebase we need to set the environment for head repo (#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> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
1 parent b383652 commit 4199d28

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

services/pull/merge.go

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

598-
env = repo_module.FullPushingEnvironment(
599-
headUser,
600-
doer,
601-
pr.BaseRepo,
602-
pr.BaseRepo.Name,
603-
pr.ID,
604-
)
605-
606598
var pushCmd *git.Command
607599
if mergeStyle == repo_model.MergeStyleRebaseUpdate {
608600
// force push the rebase result to head branch
601+
env = repo_module.FullPushingEnvironment(
602+
headUser,
603+
doer,
604+
pr.HeadRepo,
605+
pr.HeadRepo.Name,
606+
pr.ID,
607+
)
609608
pushCmd = git.NewCommand(ctx, "push", "-f", "head_repo").AddDynamicArguments(stagingBranch + ":" + git.BranchPrefix + pr.HeadBranch)
610609
} else {
610+
env = repo_module.FullPushingEnvironment(
611+
headUser,
612+
doer,
613+
pr.BaseRepo,
614+
pr.BaseRepo.Name,
615+
pr.ID,
616+
)
611617
pushCmd = git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch)
612618
}
613619

services/repository/push.go

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

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

134136
commits := repo_module.NewPushCommits()
@@ -161,7 +163,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
161163

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

167169
refName := opts.RefName()

0 commit comments

Comments
 (0)