feat(refinery): use squash merge to eliminate redundant merge commits (#856)

Replace MergeNoFF with MergeSquash in the Refinery to preserve the original
conventional commit message (feat:/fix:) from polecat branches instead of
creating "Merge polecat/... into main" commits.

Changes:
- Add MergeSquash function to internal/git/git.go
- Add GetBranchCommitMessage helper to retrieve branch commit messages
- Update engineer.go doMerge to use squash merge with original message

Fixes #855

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Advaya Krishna
2026-01-21 18:12:40 -08:00
committed by GitHub
parent b333bf8146
commit d67aa0212c
2 changed files with 34 additions and 6 deletions

View File

@@ -319,13 +319,20 @@ func (e *Engineer) doMerge(ctx context.Context, branch, target, sourceIssue stri
_, _ = fmt.Fprintln(e.output, "[Engineer] Tests passed")
}
// Step 5: Perform the actual merge
mergeMsg := fmt.Sprintf("Merge %s into %s", branch, target)
if sourceIssue != "" {
mergeMsg = fmt.Sprintf("Merge %s into %s (%s)", branch, target, sourceIssue)
// Step 5: Perform the actual merge using squash merge
// Get the original commit message from the polecat branch to preserve the
// conventional commit format (feat:/fix:) instead of creating redundant merge commits
originalMsg, err := e.git.GetBranchCommitMessage(branch)
if err != nil {
// Fallback to a descriptive message if we can't get the original
originalMsg = fmt.Sprintf("Squash merge %s into %s", branch, target)
if sourceIssue != "" {
originalMsg = fmt.Sprintf("Squash merge %s into %s (%s)", branch, target, sourceIssue)
}
_, _ = fmt.Fprintf(e.output, "[Engineer] Warning: could not get original commit message: %v\n", err)
}
_, _ = fmt.Fprintf(e.output, "[Engineer] Merging with message: %s\n", mergeMsg)
if err := e.git.MergeNoFF(branch, mergeMsg); err != nil {
_, _ = fmt.Fprintf(e.output, "[Engineer] Squash merging with message: %s\n", strings.TrimSpace(originalMsg))
if err := e.git.MergeSquash(branch, originalMsg); err != nil {
// ZFC: Use git's porcelain output to detect conflicts instead of parsing stderr.
// GetConflictingFiles() uses `git diff --diff-filter=U` which is proper.
conflicts, conflictErr := e.git.GetConflictingFiles()