fix(parse_git_status): fix false-positive detached HEAD when upstream name contains 'detached'#1374
Conversation
…pstream 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 e2b-dev#1373
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Aegis Dev.
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3b7326ed9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| is_detached = raw_branch.startswith("HEAD (detached at ") or ( | ||
| "detached" in raw_branch | ||
| ) | ||
| is_detached = raw_branch.startswith("HEAD (detached at ") |
There was a problem hiding this comment.
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 👍 / 👎.
What's broken
parse_git_statusinpackages/python-sdk/e2b/sandbox/_git/parse.pyreturnsdetached=Trueand leavescurrent_branchandupstreamempty for a repository that is not in detached HEAD mode. This happens whenever the upstream tracking branch name contains the worddetached— for example, a branchmaintrackingorigin/detached-work. The porcelain line## main...origin/detached-workcausesraw_branchto equal"main...origin/detached-work", and the condition"detached" in raw_branchon line 129 fires, sending execution into the detached-HEAD code path and returning completely wrong state.Why it happens
The
"detached" in raw_branchsub-check is a substring match against the fullbranch...upstreamstring, not just the branch name, so it matches any upstream whose name contains the worddetached.Fix
Remove the
"detached" in raw_branchsub-check from line 128–130. Theraw_branch.startswith("HEAD (detached at ")check already covers real detached HEAD, and the subsequentnormalized_branch.startswith("HEAD")check on line 130 catchesHEAD (no branch)and similar HEAD variants.Test
Added
tests/bugs/test_parse_git_status_detached.pywhich feeds## main...origin/detached-workintoparse_git_statusand assertsdetached=False,current_branch="main", andupstream="origin/detached-work".Fixes #1373