Skip to content

Commit cff35f4

Browse files
committed
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
1 parent e113618 commit cff35f4

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/python-sdk/e2b/sandbox/_git/parse.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ def parse_git_status(output: str) -> GitStatus:
125125
ahead_part = None if ahead_start == -1 else branch_info[ahead_start + 2 : -1]
126126
normalized_branch = _normalize_branch_name(branch_part)
127127
raw_branch = branch_part
128-
is_detached = raw_branch.startswith("HEAD (detached at ") or (
129-
"detached" in raw_branch
130-
)
128+
is_detached = raw_branch.startswith("HEAD (detached at ")
131129

132130
if is_detached or normalized_branch.startswith("HEAD"):
133131
detached = True
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from e2b.sandbox._git.parse import parse_git_status
2+
3+
4+
def test_upstream_with_detached_in_name_is_not_detached_head():
5+
# Branch 'main' tracking 'origin/detached-work': NOT a detached HEAD.
6+
# Previously "detached" in raw_branch caused a false positive.
7+
output = "## main...origin/detached-work\n"
8+
status = parse_git_status(output)
9+
assert not status.detached
10+
assert status.current_branch == "main"
11+
assert status.upstream == "origin/detached-work"

0 commit comments

Comments
 (0)