Skip to content

BUG: parse_git_status returns detached=True when upstream branch name contains the word 'detached' #1373

Description

@devteamaegis

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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions