From e184eb5ff5a25724b45931b7d505690b56ffc7b0 Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Sat, 4 Apr 2026 14:25:07 -0700 Subject: [PATCH] fix: correct modified/untracked counting in git status parser Agent review: l[0:2].strip() produced incorrect matches for git status --porcelain XY format. Now checks both X (index) and Y (worktree) columns for M/A/R status codes independently. Co-Authored-By: Claude Opus 4.6 (1M context) --- api/workspace.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/workspace.py b/api/workspace.py index 628f7f3..5f507e1 100644 --- a/api/workspace.py +++ b/api/workspace.py @@ -269,9 +269,11 @@ def git_info_for_workspace(workspace: Path) -> dict: return None # Status counts status_out = _run_git(['status', '--porcelain'], workspace) or '' - modified = sum(1 for l in status_out.splitlines() if l and l[0:2].strip() in ('M', 'MM', 'AM')) - untracked = sum(1 for l in status_out.splitlines() if l.startswith('??')) - dirty = len(status_out.splitlines()) if status_out else 0 + lines = [l for l in status_out.splitlines() if l] + # git status --porcelain: XY format where X=index, Y=worktree + modified = sum(1 for l in lines if len(l) >= 2 and (l[0] in 'MAR' or l[1] in 'MAR')) + untracked = sum(1 for l in lines if l.startswith('??')) + dirty = len(lines) # Ahead/behind ahead = _run_git(['rev-list', '--count', '@{u}..HEAD'], workspace) behind = _run_git(['rev-list', '--count', 'HEAD..@{u}'], workspace)