Share commit preparation and checkout updates across merge paths

This commit is contained in:
Ian Gulliver
2026-10-21 12:13:04 -07:00
parent 8c16bc3fb0
commit e82a9f9ef7
3 changed files with 77 additions and 71 deletions
+3 -50
View File
@@ -330,12 +330,7 @@ func (m *Manager) landMerge(ctx context.Context, f store.FinalizingMerge) error
if err != nil {
return err
}
coAuthors, err := m.CoAuthors(ctx, task.Id, f.By)
if err != nil {
return err
}
env := git.IdentityEnv(user.GitName, user.GitEmail)
commit, err = git.SquashCommit(project.RepoPath, task.WorktreePath, project.DefaultBranch, squashMessage(task.MergeTitle, coAuthors), env, m.signer(ctx, user))
commit, notes, err = m.prepareMainCommit(ctx, task, project, user)
if err != nil {
return err
}
@@ -346,15 +341,6 @@ func (m *Manager) landMerge(ctx context.Context, f store.FinalizingMerge) error
}
return m.closeUnchanged(ctx, task, project, f.By)
}
note, err := m.mergeNote(ctx, task, f.By)
if err != nil {
return err
}
notes, err = git.NoteCommit(project.RepoPath, commit, note, env)
if err != nil {
return err
}
err = m.store.SetFinalizingCommit(ctx, task.Id, commit, notes)
if err != nil {
return err
@@ -391,13 +377,9 @@ func (m *Manager) closeUnchanged(ctx context.Context, task api.Task, project api
func (m *Manager) closePushed(ctx context.Context, task api.Task, project api.Project, commit, notes, login string) error {
pushed := git.Remote + "/" + project.DefaultBranch
err := git.AdvanceNotes(project.RepoPath, notes)
err := advanceMainCheckout(project, commit, notes)
if err != nil {
return &unfinishedMergeError{fmt.Errorf("pushed %s to %s, but updating %s in the project checkout failed: %w", commit, pushed, git.NotesRef, err)}
}
err = git.FastForward(project.RepoPath, commit)
if err != nil {
return &unfinishedMergeError{fmt.Errorf("pushed %s to %s, but fast-forwarding the project checkout failed: %w", commit, pushed, err)}
return &unfinishedMergeError{err}
}
err = m.RemoveTask(ctx, task, project, login)
if err != nil {
@@ -410,35 +392,6 @@ func (m *Manager) closePushed(ctx context.Context, task api.Task, project api.Pr
return nil
}
func (m *Manager) CoAuthors(ctx context.Context, taskID, login string) ([]api.Participant, error) {
participants, err := m.store.Participants(ctx, taskID)
if err != nil {
return nil, err
}
coAuthors := []api.Participant{}
for _, p := range participants {
if p.Login != login {
coAuthors = append(coAuthors, p)
}
}
return coAuthors, nil
}
func squashMessage(title string, coAuthors []api.Participant) string {
trailers := []string{}
for _, p := range coAuthors {
if p.GitName == "" || p.GitEmail == "" {
continue
}
trailers = append(trailers, fmt.Sprintf("Co-authored-by: %s <%s>", p.GitName, p.GitEmail))
}
if len(trailers) == 0 {
return title
}
return title + "\n\n" + strings.Join(trailers, "\n")
}
func (m *Manager) RemoveTask(ctx context.Context, task api.Task, project api.Project, actor string) error {
err := m.StopTask(ctx, task.Id, actor)
if err != nil {