Repository metrics
- Stars
- (48,085 stars)
- PR merge metrics
- (平均マージ 11d 1h) (30d で 45 merged PRs)
説明
:robot: This was written by an AI agent on behalf of @paolomainardi.
Description
When HEAD is detached, rtk git status shows * HEAD (no branch) instead of the actual commit SHA. Raw git status shows HEAD detached at 77a04d3.
The SHA is critical for AI agents — without it, the agent cannot identify which commit it is on in detached HEAD state (common during rebase, bisect, CI pipelines, and checkout of specific commits).
Root Cause
run_status() uses git status --porcelain -b, which reports detached HEAD as:
## HEAD (no branch)
Porcelain v1 does not include the SHA for detached HEAD. format_status_output() passes this through as-is, losing the SHA.
The raw status output (git status without --porcelain) — which is already captured in run_status() for tracking — contains the full info:
HEAD detached at 77a04d3
Reproduction
git checkout HEAD~2
# Raw: shows the SHA
git status | head -1
# Output: HEAD detached at 77a04d3
# RTK: SHA is lost
rtk git status | head -1
# Output: * HEAD (no branch)
Fix
After formatting the porcelain output, check for HEAD (no branch) and replace it with the HEAD detached at <sha> line from the raw output (already available in run_status()). This follows the same pattern used by extract_state_header() to recover rebase/merge state from raw output.
Impact
- Severity: Medium — agents cannot identify their position in detached HEAD state
- Token cost: +8 bytes — negligible
- Version: Verified on v0.39.0