feat(js-sdk): add git.log() for commit history#1556
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @Rehansanjay 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 detectedLatest commit: 9c0e1d7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46df70f993
ℹ️ 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".
| * @param opts Log options. | ||
| * @returns List of parsed commits. | ||
| */ | ||
| async log(path: string, opts?: GitLogOpts): Promise<GitCommit[]> { |
There was a problem hiding this comment.
Add git.log to both Python clients
The repository's AGENTS.md requires SDK changes to be applied to the JS SDK and both sync and async Python implementations. A repo-wide search finds no log method or GitCommit type under packages/python-sdk; both Python Git clients still go directly from status to branches (sandbox_sync/git.py:437-468 and sandbox_async/git.py:445-476). Add the shared Python parsing/type support, both client methods, and equivalent tests so this feature actually provides the required SDK parity.
Useful? React with 👍 / 👎.
| const result = await this.runGit(args, path, rest) | ||
| return parseGitLog(result.stdout) |
There was a problem hiding this comment.
Return an empty history for an unborn branch
When path is a valid repository created by git init but has no commits, Git 2.43 exits with status 128 (fatal: your current branch ... does not have any commits yet), so Commands.run throws here before parseGitLog can return the empty array that its new test covers. Handle the unborn-HEAD case explicitly so git.log() returns [] for an empty repository instead of rejecting.
Useful? React with 👍 / 👎.
| if (maxCount !== undefined) { | ||
| if (maxCount <= 0) { | ||
| throw new InvalidArgumentError('maxCount must be a positive number.') | ||
| } | ||
| args.push('-n', maxCount.toString()) |
There was a problem hiding this comment.
Reject non-finite and fractional maxCount values
When maxCount is NaN, Infinity, or a positive fraction, the <= 0 check passes even though Git's count option is documented by git rev-list -h as --max-count=<n>. Git 2.43 silently treats -n NaN/-n Infinity as zero and truncates -n 1.5 to one, so computed invalid inputs can return an incorrect history rather than the promised argument error; validate that the value is a finite positive integer before invoking Git.
Useful? React with 👍 / 👎.
|
We're not accepting git related contributions atm. |
Summary
Adds
Sandbox.git.log()to the JS/TS SDK, returning parsed commit history (GitCommit[]) for a repository inside the sandbox:This completes SDK parity between the Python SDK (
Sandbox.git.log(), PR #1528) and the TypeScript SDK.Implementation Details
packages/js-sdk/src/sandbox/git/utils.ts:GitCommitinterface (hash,authorName,authorEmail,date,message).parseGitLog(stdout: string): GitCommit[]using unit-separator (%x1f) pretty formatting (%H%x1f%an%x1f%ae%x1f%aI%x1f%s) to parse fields safely without split errors on spaces.packages/js-sdk/src/sandbox/git/index.ts:GitLogOptsinterface supportingmaxCountandGitRequestOpts.async log(path: string, opts?: GitLogOpts): Promise<GitCommit[]>method toGitclass.packages/js-sdk/src/index.ts:GitCommit,GitLogOpts, andparseGitLog.packages/js-sdk/tests/sandbox/git/log.test.ts:maxCount <= 0), andcommands.runargument formatting..changeset/git-log-history.md:e2b.Pre-flight Checklist
pnpm run format— prettier check clean on modified filespnpm run lint—oxlintclean (0 errors, 0 warnings across 141 files)pnpm run typecheck—tsc --noEmitcleanvitest run tests/sandbox/git/log.test.ts(4/4 passed).changeset/git-log-history.md(e2b: minor)