diff --git a/packages/python-sdk/e2b/sandbox/_git/parse.py b/packages/python-sdk/e2b/sandbox/_git/parse.py index e6cea693af..7ae83ce2c1 100644 --- a/packages/python-sdk/e2b/sandbox/_git/parse.py +++ b/packages/python-sdk/e2b/sandbox/_git/parse.py @@ -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 ") if is_detached or normalized_branch.startswith("HEAD"): detached = True diff --git a/packages/python-sdk/tests/bugs/test_parse_git_status_detached.py b/packages/python-sdk/tests/bugs/test_parse_git_status_detached.py new file mode 100644 index 0000000000..4695af8bd4 --- /dev/null +++ b/packages/python-sdk/tests/bugs/test_parse_git_status_detached.py @@ -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"