Skip to content

cli: try squash merge first, fall back to merge commit if not allowed#25609

Merged
pelikhan merged 3 commits intomainfrom
copilot/support-merging-via-squash
Apr 10, 2026
Merged

cli: try squash merge first, fall back to merge commit if not allowed#25609
pelikhan merged 3 commits intomainfrom
copilot/support-merging-via-squash

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Repositories that restrict merge commits fail the gh pr merge --merge call with GraphQL: Merge commits are not allowed on this repository. — making gh aw add unable to auto-merge the setup PR.

Changes

  • mergePullRequest merge strategy — attempts squash merge first (--squash); if the repository does not permit squash merges, detects the GitHub GraphQL error (case-insensitive, checked against both combined output and error string) and retries with a merge commit (--merge)
  • squashMergeNotAllowedErr constant — names the expected error substring for clarity and easy updates if the API message ever changes
  • Informs the user via console.FormatInfoMessage before the retry so the strategy change is visible

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot try squash merge first

Copilot AI changed the title [WIP] Support merging via squash by default cli: fall back to squash merge when merge commits are not allowed Apr 10, 2026
Copilot AI requested a review from pelikhan April 10, 2026 11:09
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot try squash merge first

Done in 68d7c2e. Squash merge is now attempted first; if the repo doesn't allow squash merges, it falls back to a merge commit.

Copilot AI changed the title cli: fall back to squash merge when merge commits are not allowed cli: try squash merge first, fall back to merge commit if not allowed Apr 10, 2026
@pelikhan pelikhan marked this pull request as ready for review April 10, 2026 11:19
Copilot AI review requested due to automatic review settings April 10, 2026 11:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the interactive add flow’s PR auto-merge behavior to handle repositories with merge-method restrictions by trying squash merges first and retrying with a merge commit when squash merges are disallowed.

Changes:

  • Add detection for “squash merges are not allowed” errors from gh pr merge --squash.
  • Attempt gh pr merge --squash first, and fall back to --merge on the detected restriction.
  • Print an informational message when switching strategies so the retry is visible to the user.
Show a summary per file
File Description
pkg/cli/add_interactive_git.go Implements squash-first merge strategy with fallback to merge-commit when squash merges aren’t permitted.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

pkg/cli/add_interactive_git.go:305

  • If the fallback --merge attempt fails, the returned error only includes the merge-commit output, losing the original squash failure context (and why the retry happened). Consider including both the initial squash error/output and the merge-commit error/output in the final error, so diagnosis doesn’t depend on having seen the transient stderr info message.
	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))
		}
  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines 289 to +291
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")
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.
@pelikhan pelikhan merged commit f4b234c into main Apr 10, 2026
75 of 76 checks passed
@pelikhan pelikhan deleted the copilot/support-merging-via-squash branch April 10, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: support merging via squash

3 participants