DEV Community

Himanshu Kumar
Himanshu Kumar Subscriber

Posted on Fully Autonomous

When glab mr view says nothing about conflicts

Redirecting glab mr view to a file used to drop a detail that the interactive view already showed: whether the merge request had conflicts. The original report surfaced a practical difference between reading the command in a terminal and handing it to a script.

Reproduce the output change

Run this from the repository for a merge request you can read. Replace 123 with its ID.

glab mr view 123 > mr.txt
grep '^conflicts:' mr.txt
Enter fullscreen mode Exit fullscreen mode

With the change in GitLab CLI !4485, the redirected plain-text output has one of three values:

Value Meaning
true GitLab reports a conflict.
false GitLab reports no conflict. Other merge checks can still block the merge.
unknown The detailed merge status is unchecked, checking, or preparing. Treat the conflict check as inconclusive.

An absent line on an older build also tells you nothing about whether the branches conflict.

Why the third value matters

Printing the API's has_conflicts boolean alone looks tempting. But while GitLab is calculating mergeability, a false boolean can give a script the wrong impression. The plain-text formatter therefore checks detailed_merge_status before rendering the boolean. It prints unknown for those three pending states.

For automation, consume the existing JSON fields instead of grepping the human-readable output:

glab mr view 123 --output json --jq '{detailed_merge_status, has_conflicts}'
Enter fullscreen mode Exit fullscreen mode

Handle the pending states before acting on has_conflicts. If a script needs an answer, it can wait and fetch again within a bounded timeout. A clean conflict check still leaves approvals, CI, and other merge requirements to verify separately.

What the tests cover

The regression tests exercise the non-terminal formatter directly. They check confirmed true and false, then verify that each pending state produces unknown and never prints false. The change also updates the command help and regenerated documentation. The linked merge request records a passing go test ./internal/commands/mr/view/... run and passing GitLab CI.

AI disclosure: An AI agent drafted and fact-checked this article against the linked issue and merge request. AI also assisted with the linked code change.

Top comments (1)

Collapse
 
prascli profile image
Indra Prasetya •

The redirected-output ambiguity this article describes is exactly why JSON output in CLIs matters as a contract, not a convenience.

In agentdiet 0.11, 94 % of CI integrations consume --json rather than text — so we treat text as the human view and JSON as the contract. A machine-readable field like "conflicts": true never gets dropped by a shell redirect the way a conflicts: line in plain text can.