Skip to content

fix(git): prevent crash on malformed branch lines and false detached HEAD detection#1521

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/parse-git-status-branch-detection
Open

fix(git): prevent crash on malformed branch lines and false detached HEAD detection#1521
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/parse-git-status-branch-detection

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Fixes two bugs in parseGitStatus / parse_git_status for both Python and JS SDKs:

Bug 1: Crash on branch lines containing multiple ... (#1371)

split("...") without a limit causes a ValueError (Python) or incorrect destructuring (JS) when the normalized branch line contains more than one ... sequence.

Fix:

  • Python: split("...", 1) to limit the split
  • JS: Use indexOf("...") + slice() instead of destructuring split("...")

Bug 2: False detached HEAD detection (#1373)

The broad substring check "detached" in raw_branch (Python) / rawBranch.includes('detached') (JS) incorrectly identifies branches like fix-detached-bug or feature/detached-mode as detached HEAD state.

Fix: Remove the overly broad substring check, keeping only the precise startsWith("HEAD (detached at ") check which matches git's actual output format.

Tests

Added 10 unit tests for each SDK covering edge cases:

  • Extra dots in branch upstream causing crash
  • Upstream containing "detached" substring
  • Branch named with "detached" substring
  • Real detached HEAD state
  • No commits yet / HEAD with no branch
  • Simple branch without upstream
  • Empty output
  • Normal branch with upstream

Fixes #1371, fixes #1373
/cc @mishushakov Would appreciate your review, thanks!

…HEAD detection

- Use split('...', 1) / indexOf('...') to avoid ValueError when the
  branch line contains multiple '...' sequences (e2b-dev#1371)
- Remove overly broad 'detached' substring check that misidentified
  branches like 'fix-detached-bug' as detached HEAD (e2b-dev#1373)
- Add unit tests for both Python and JS SDKs covering edge cases

Fixes e2b-dev#1371, fixes e2b-dev#1373
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f3a47ab

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

This PR includes changesets to release 2 packages
Name Type
e2b Patch
@e2b/python-sdk 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

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

Projects

None yet

2 participants