Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions pkg/cli/add_interactive_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,34 @@ func (c *AddInteractiveConfig) checkCleanWorkingDirectory() error {
return nil
}

// mergePullRequest merges the specified PR
// squashMergeNotAllowedErr is the lowercase substring of the GitHub GraphQL API error
// returned when a repository does not permit squash merges. It is used to detect when
// a squash merge should be retried with a merge-commit strategy.
const squashMergeNotAllowedErr = "squash merges are not allowed"

// mergePullRequest merges the specified PR, attempting a squash merge first and
// falling back to a merge commit if squash merges are not allowed on the repository.
func (c *AddInteractiveConfig) mergePullRequest(prNumber int) error {
output, err := workflow.RunGHCombined("Merging pull request...", "pr", "merge", strconv.Itoa(prNumber), "--repo", c.RepoOverride, "--merge")
if err != nil {
return fmt.Errorf("merge failed: %w (output: %s)", err, string(output))
prArg := strconv.Itoa(prNumber)
squashOutput, squashErr := workflow.RunGHCombined("Merging pull request (squash)...", "pr", "merge", prArg, "--repo", c.RepoOverride, "--squash")
Comment on lines 289 to +291
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned error message always says "merge failed" even when the attempted strategy was a squash merge. This makes troubleshooting harder (e.g., users can’t tell whether the failure came from --squash vs the retry path). Consider making the error text strategy-specific (e.g., "squash merge failed") so the surfaced error matches what was attempted.

This issue also appears on line 300 of the same file.

Copilot uses AI. Check for mistakes.
if squashErr == nil {
return nil
}
return nil

// If squash merges are not allowed on this repository (e.g. only merge commits or rebase
// merges are enabled), fall back to a merge commit. The error text comes from the GitHub
// GraphQL API and is surfaced verbatim in the gh CLI output.
combinedText := strings.ToLower(string(squashOutput) + squashErr.Error())
if strings.Contains(combinedText, squashMergeNotAllowedErr) {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Squash merges are not allowed on this repository, retrying with merge commit"))
mergeOutput, mergeErr := workflow.RunGHCombined("Merging pull request...", "pr", "merge", prArg, "--repo", c.RepoOverride, "--merge")
if mergeErr != nil {
return fmt.Errorf("merge failed: %w (output: %s)", mergeErr, string(mergeOutput))
}
return nil
}

return fmt.Errorf("merge failed: %w (output: %s)", squashErr, string(squashOutput))
}

// editPRTitle updates the title of the specified PR via the gh CLI.
Expand Down
Loading