GitLab auto-merge fails: glab mr merge uses nonexistent --should-remove-source-branch flag #284

Closed
opened 2026-08-19 01:45:09 +00:00 by david · 1 comment
Owner

Root Cause

src/mr/services/gitlabMergePoller.tsGitLabMergePoller.merge() hardcodes:

glab mr merge <mrNumber> --should-remove-source-branch

--should-remove-source-branch is not a real glab flag. Confirmed via:

  • Local glab help mr merge (v1.110.0)
  • Official glab mr merge --help docs

The correct flag is -d, --remove-source-branch.

glab's cobra parser rejects the unknown flag before merging, dumping a usage/help block to stderr. This causes 100% of GitLab auto-merge attempts to fail — not transient/version-drift, present since inception (likely confusing GitLab REST's should_remove_source_branch JSON field with glab's actual CLI flag name).

Observed Failure

[10:52 mr] Auto-merge failed for teg/ovation-technology/development/ignition-2.0-dotnet-poc#5:
glab command failed: Command failed: glab mr merge 5
Unknown flag: usage.

(Full glab usage dump is truncated/mangled by makeCliRunner's error wrapping — see fix item 3 below.)

Blast Radius

GitLab-only.

  • githubMergePoller.ts (gh pr merge --merge --auto) — valid flags, unaffected.
  • forgejoMergePoller.ts — pure REST call, no CLI flags, unaffected.

Fix Scope (full hardening)

  1. Rename --should-remove-source-branch--remove-source-branch in gitlabMergePoller.ts.
  2. Fix gitlabMergePoller.test.ts's test that currently asserts the buggy flag string ('glab:mr merge 42 --should-remove-source-branch' and its toHaveBeenCalledWith assertion) — otherwise the regression test keeps the bug locked in.
  3. Harden makeCliRunner (cliMergePollerBase.ts) to append captured stderr to the MrClientError message when present, e.g. `${command} command failed: ${message}\nstderr: ${stderr}` — no new fields added, fully backward compatible with existing consumers/tests.
  4. Add an inline code comment above the flag in gitlabMergePoller.ts documenting the correct flag name and linking to https://docs.gitlab.com/cli/mr/merge/, warning future editors to verify against glab help mr merge before changing it.

Verification

Unit tests only:

  • Update/add vitest coverage for the corrected flag (gitlabMergePoller.test.ts) and the stderr-appended error message (cliMergePollerBase.test.ts).
  • Run npm test and npm run lint to confirm green.
  • No live GitLab MR verification required — matches pi-loop's deterministic-seam testing philosophy (AGENTS.md).
## Root Cause `src/mr/services/gitlabMergePoller.ts` → `GitLabMergePoller.merge()` hardcodes: ``` glab mr merge <mrNumber> --should-remove-source-branch ``` `--should-remove-source-branch` is **not a real glab flag**. Confirmed via: - Local `glab help mr merge` (v1.110.0) - Official `glab mr merge --help` docs The correct flag is `-d, --remove-source-branch`. glab's cobra parser rejects the unknown flag before merging, dumping a usage/help block to stderr. This causes 100% of GitLab auto-merge attempts to fail — not transient/version-drift, present since inception (likely confusing GitLab REST's `should_remove_source_branch` JSON field with glab's actual CLI flag name). ## Observed Failure ``` [10:52 mr] Auto-merge failed for teg/ovation-technology/development/ignition-2.0-dotnet-poc#5: glab command failed: Command failed: glab mr merge 5 Unknown flag: usage. ``` (Full glab usage dump is truncated/mangled by `makeCliRunner`'s error wrapping — see fix item 3 below.) ## Blast Radius **GitLab-only.** - `githubMergePoller.ts` (`gh pr merge --merge --auto`) — valid flags, unaffected. - `forgejoMergePoller.ts` — pure REST call, no CLI flags, unaffected. ## Fix Scope (full hardening) 1. Rename `--should-remove-source-branch` → `--remove-source-branch` in `gitlabMergePoller.ts`. 2. Fix `gitlabMergePoller.test.ts`'s test that currently asserts the buggy flag string (`'glab:mr merge 42 --should-remove-source-branch'` and its `toHaveBeenCalledWith` assertion) — otherwise the regression test keeps the bug locked in. 3. Harden `makeCliRunner` (`cliMergePollerBase.ts`) to append captured stderr to the `MrClientError` message when present, e.g. `` `${command} command failed: ${message}\nstderr: ${stderr}` `` — no new fields added, fully backward compatible with existing consumers/tests. 4. Add an inline code comment above the flag in `gitlabMergePoller.ts` documenting the correct flag name and linking to https://docs.gitlab.com/cli/mr/merge/, warning future editors to verify against `glab help mr merge` before changing it. ## Verification Unit tests only: - Update/add vitest coverage for the corrected flag (`gitlabMergePoller.test.ts`) and the stderr-appended error message (`cliMergePollerBase.test.ts`). - Run `npm test` and `npm run lint` to confirm green. - No live GitLab MR verification required — matches pi-loop's deterministic-seam testing philosophy (AGENTS.md).
david closed this issue 2026-08-19 02:04:22 +00:00
Author
Owner

pi-loop opened and merged a pull request for this issue: #285

pi-loop opened and merged a pull request for this issue: https://git.excelera.net/david/pi-loop/pulls/285
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
david/pi-loop#284
No description provided.