What breaks
parse_git_status in packages/python-sdk/e2b/sandbox/_git/parse.py incorrectly sets detached=True and leaves current_branch/upstream unpopulated for a repository that is not in detached HEAD mode when the upstream tracking branch name contains the word detached (e.g., origin/detached-work).
When branch main tracks origin/detached-work, git status --porcelain=1 -b outputs ## main...origin/detached-work. The variable raw_branch is set to "main...origin/detached-work", so the condition "detached" in raw_branch on line 129 evaluates to True, triggering the detached-HEAD code path and returning completely wrong state.
AssertionError: BUG: 'detached' in upstream name causes false-positive: is_detached=True
Root cause
Line 128-130 in parse.py:
is_detached = raw_branch.startswith("HEAD (detached at ") or (
"detached" in raw_branch
)
The "detached" in raw_branch sub-check matches any upstream ref whose name contains the word detached, not just actual detached-HEAD porcelain output.
Fix
Remove the "detached" in raw_branch sub-check. The raw_branch.startswith("HEAD (detached at ") check is sufficient for real detached HEAD, and the subsequent normalized_branch.startswith("HEAD") check on line 130 catches HEAD (no branch) and other HEAD variants.
What breaks
parse_git_statusinpackages/python-sdk/e2b/sandbox/_git/parse.pyincorrectly setsdetached=Trueand leavescurrent_branch/upstreamunpopulated for a repository that is not in detached HEAD mode when the upstream tracking branch name contains the worddetached(e.g.,origin/detached-work).When branch
maintracksorigin/detached-work,git status --porcelain=1 -boutputs## main...origin/detached-work. The variableraw_branchis set to"main...origin/detached-work", so the condition"detached" in raw_branchon line 129 evaluates toTrue, triggering the detached-HEAD code path and returning completely wrong state.Root cause
Line 128-130 in
parse.py:The
"detached" in raw_branchsub-check matches any upstream ref whose name contains the worddetached, not just actual detached-HEAD porcelain output.Fix
Remove the
"detached" in raw_branchsub-check. Theraw_branch.startswith("HEAD (detached at ")check is sufficient for real detached HEAD, and the subsequentnormalized_branch.startswith("HEAD")check on line 130 catchesHEAD (no branch)and other HEAD variants.