From cff35f47ff67db8982345c6aafbf6ca3e192f470 Mon Sep 17 00:00:00 2001 From: devteamaegis Date: Sun, 31 May 2026 18:13:47 -0400 Subject: [PATCH] fix(parse_git_status): remove false-positive detached HEAD check on upstream name The broad `"detached" in raw_branch` sub-check matched any upstream tracking ref containing the word "detached" (e.g. `origin/detached-work`), causing `parse_git_status` to return `detached=True` and empty `current_branch`/`upstream` for repos that are not in detached HEAD mode. Remove the sub-check; `raw_branch.startswith("HEAD (detached at ")` already covers the real detached-HEAD case and the subsequent `normalized_branch.startswith("HEAD")` covers `HEAD (no branch)` variants. Fixes #1373 --- packages/python-sdk/e2b/sandbox/_git/parse.py | 4 +--- .../tests/bugs/test_parse_git_status_detached.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 packages/python-sdk/tests/bugs/test_parse_git_status_detached.py 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"