Share commit preparation and checkout updates across merge paths
This commit is contained in:
@@ -116,12 +116,8 @@ func (m *Manager) pushToMain(ctx context.Context, l *live, task api.Task, projec
|
||||
return "", err
|
||||
}
|
||||
|
||||
coAuthors, err := m.CoAuthors(ctx, task.Id, user.Login)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
env := git.IdentityEnv(user.GitName, user.GitEmail)
|
||||
commit, err := git.SquashCommit(project.RepoPath, l.dir, project.DefaultBranch, squashMessage(title, coAuthors), env, m.signer(ctx, user))
|
||||
task.MergeTitle = title
|
||||
commit, notes, err := m.prepareMainCommit(ctx, task, project, user)
|
||||
conflict := &git.ConflictError{}
|
||||
if errors.As(err, &conflict) {
|
||||
return "", fmt.Errorf("%w; run `git merge --no-ff --no-commit %s`, resolve them, and call merge_to_main again", err, project.DefaultBranch)
|
||||
@@ -134,15 +130,6 @@ func (m *Manager) pushToMain(ctx context.Context, l *live, task api.Task, projec
|
||||
return "", err
|
||||
}
|
||||
|
||||
task.MergeTitle = title
|
||||
note, err := m.mergeNote(ctx, task, user.Login)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
notes, err := git.NoteCommit(project.RepoPath, commit, note, env)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = git.Push(ctx, project.RepoPath, commit, project.DefaultBranch, notes)
|
||||
if errors.Is(err, git.ErrRemoteMoved) {
|
||||
return "", fmt.Errorf("%w; call merge_to_main again", err)
|
||||
@@ -152,13 +139,9 @@ func (m *Manager) pushToMain(ctx context.Context, l *live, task api.Task, projec
|
||||
}
|
||||
|
||||
pushed := git.Remote + "/" + project.DefaultBranch
|
||||
err = git.AdvanceNotes(project.RepoPath, notes)
|
||||
err = advanceMainCheckout(project, commit, notes)
|
||||
if err != nil {
|
||||
return "", 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 "", fmt.Errorf("pushed %s to %s, but fast-forwarding the project checkout failed: %w", commit, pushed, err)
|
||||
return "", err
|
||||
}
|
||||
err = git.Merge(l.dir, commit, fmt.Sprintf("Merge %s from %s", commit[:7], project.DefaultBranch), l.gitName, l.gitEmail)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user