Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/python-sdk/e2b/sandbox/_git/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def parse_git_status(output: str) -> GitStatus:
ahead_part = None if ahead_start == -1 else branch_info[ahead_start + 2 : -1]
normalized_branch = _normalize_branch_name(branch_part)
raw_branch = branch_part
is_detached = raw_branch.startswith("HEAD (detached at ") or (
"detached" in raw_branch
)
is_detached = raw_branch.startswith("HEAD (detached at ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the detached fix to the JS SDK too

This change fixes parse_git_status only for Python, but the JS SDK still has the same rawBranch.includes('detached') check in packages/js-sdk/src/sandbox/git/utils.ts:392-394, so parseGitStatus('## main...origin/detached-work\n') still reports a detached HEAD for JS users. The repo instructions say SDK changes should be applied to both JS and Python implementations, and this leaves the same user-visible status bug in one of the shipped SDKs.

Useful? React with 👍 / 👎.


if is_detached or normalized_branch.startswith("HEAD"):
detached = True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from e2b.sandbox._git.parse import parse_git_status


def test_upstream_with_detached_in_name_is_not_detached_head():
# Branch 'main' tracking 'origin/detached-work': NOT a detached HEAD.
# Previously "detached" in raw_branch caused a false positive.
output = "## main...origin/detached-work\n"
status = parse_git_status(output)
assert not status.detached
assert status.current_branch == "main"
assert status.upstream == "origin/detached-work"