Skip to content

fix(sdk): parse detached upstream names correctly - #1763

Closed
tgolob wants to merge 2 commits into
e2b-dev:mainfrom
tgolob:fix/git-status-detached-upstream
Closed

fix(sdk): parse detached upstream names correctly#1763
tgolob wants to merge 2 commits into
e2b-dev:mainfrom
tgolob:fix/git-status-detached-upstream

Conversation

@tgolob

@tgolob tgolob commented Aug 22, 2026

Copy link
Copy Markdown

Summary

  • Parse detached Git branches consistently in the JavaScript and Python SDKs.
  • Preserve currentBranch / upstream for attached branches whose names contain detached or begin with HEAD.
  • Keep the existing detached-HEAD forms (HEAD (detached at <commit>) and HEAD (no branch)) recognized.

Why

parseGitStatus used substring and prefix heuristics that could classify an attached branch such as main...origin/detached-work or HEADless-refactor...origin/HEADless-refactor as detached. That incorrectly removed the branch and upstream values from the SDK result.

This change keeps the JavaScript and Python implementations in lockstep, centralizes the detached-HEAD marker, and narrows the normalized HEAD check to the exact value emitted for (no branch).

Fixes #1373

Validation

  • JS Vitest detached-branch parser tests: 4 passed
  • Python pytest detached-branch parser tests: 4 passed
  • TypeScript type-check
  • Prettier and Oxlint
  • Ruff and Python compilation
  • git diff --check

@tgolob
tgolob requested a review from mishushakov as a code owner August 22, 2026 13:40
@cla-bot

cla-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @tgolob on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@changeset-bot

changeset-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5273f0f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@e2b/python-sdk Patch
e2b Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tgolob

tgolob commented Aug 22, 2026

Copy link
Copy Markdown
Author

Reviewer doubt: the JavaScript parser had the same substring heuristic as Python, so this patch fixes both SDKs even though the issue was reported against Python. Please confirm that the cross-SDK parity change and the shared patch changeset are the preferred release scope.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TASTE.md review of the detached-upstream parsing fix.

Principles checked: parity across JS / sync Python / async Python (T-1, T-2), naming and casing (T-9, T-12), SDK vocabulary written down in one place (T-15), no leakage into the public surface (T-18, T-19, T-20), docstrings (T-69, T-71, T-72), changeset/deprecation hygiene (T-65 – T-68).

Violations: 2 — the same one in both SDKs: the detached-HEAD marker HEAD (detached at is a piece of the SDK's own vocabulary that the parser dispatches on, and it is now spelled as a bare literal in two places per SDK (normalizeBranchName / _normalize_branch_name and the new isDetached / is_detached line). T-15 wants that set written down once, so the two dispatch sites can't drift; the leftover rawBranch / raw_branch alias also no longer buys anything now that the includes('detached') arm is gone.

Not tied to a changed line:

  • The fix removes the detached substring false positive but leaves the sibling arm normalizedBranch.startsWith('HEAD') (js utils.ts:386, parse.py:130), which misclassifies the same way for a real branch whose name begins with HEAD## HEADless-refactor...origin/HEADless-refactor still reports detached: true with no currentBranch / upstream. After normalization the only legitimate HEAD values are exactly HEAD (from HEAD (no branch)) and the detached-at SHA, so an equality check against the two known forms would close the class of bug this PR is fixing rather than half of it.
  • Otherwise compliant: no public surface change, JS and Python move in lockstep (T-1, T-2) with mirrored unit tests, and the changeset covers both published packages.

The detached field's doc (utils.ts:75, types.py:40) is also a T-72 candidate — "Whether HEAD is detached" restates the field name and doesn't say that currentBranch/upstream are undefined/None in that case, which is what a caller hitting this bug needed to know. Pre-existing, so out of scope here, but this PR is the natural place to settle it.

Comment thread packages/js-sdk/src/sandbox/git/utils.ts Outdated
Comment thread packages/python-sdk/e2b/sandbox/_git/parse.py Outdated
@tgolob

tgolob commented Aug 22, 2026

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Aug 22, 2026
@cla-bot

cla-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@tgolob

tgolob commented Aug 22, 2026

Copy link
Copy Markdown
Author

Addressed the review feedback in commit 5273f0f4:

  • Added shared DETACHED_HEAD_PREFIX / _DETACHED_HEAD_PREFIX constants and removed the now-unused raw branch aliases in both SDKs.
  • Replaced the broad startsWith('HEAD') check with an exact normalized HEAD check, so branch names such as HEADless-refactor remain attached while HEAD (no branch) and detached-at markers are still recognized.
  • Added mirrored JS/Python regression tests for the HEADless-* case and detached HEAD (no branch) case.
  • Clarified the detached-field documentation that branch/upstream values are absent when detached.

Validation: JS Vitest 4/4, Python pytest 4/4, TypeScript, Prettier, Oxlint, Ruff, Python compile, and git diff --check all pass.

@mishushakov

Copy link
Copy Markdown
Member

Hey there,
thanks for opening a PR, but we aren't currently accepting contributions to our Git integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: parse_git_status returns detached=True when upstream branch name contains the word 'detached'

2 participants