當 glab mr view 沒有顯示合併請求衝突資訊時
When glab mr view says nothing about conflicts
GitLab CLI !4485 修正 glab mr view 將輸出重新導向至檔案時遺漏衝突狀態的問題,純文字輸出現在會顯示 true、false 或 unknown。
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
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}'
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.
來源:DEV Community · dev.to