Skip to content

feat(js-sdk): add git.log() for commit history#1556

Closed
Rehansanjay wants to merge 2 commits into
e2b-dev:mainfrom
Rehansanjay:feat/js-sdk-git-log
Closed

feat(js-sdk): add git.log() for commit history#1556
Rehansanjay wants to merge 2 commits into
e2b-dev:mainfrom
Rehansanjay:feat/js-sdk-git-log

Conversation

@Rehansanjay

Copy link
Copy Markdown

Summary

Adds Sandbox.git.log() to the JS/TS SDK, returning parsed commit history (GitCommit[]) for a repository inside the sandbox:

const commits = await sandbox.git.log('/repo/path', { maxCount: 10 })
for (const commit of commits) {
  console.log(commit.hash, commit.authorName, commit.date, commit.message)
}

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:
    • Defined GitCommit interface (hash, authorName, authorEmail, date, message).
    • Added 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:
    • Added GitLogOpts interface supporting maxCount and GitRequestOpts.
    • Added async log(path: string, opts?: GitLogOpts): Promise<GitCommit[]> method to Git class.
  • packages/js-sdk/src/index.ts:
    • Exported GitCommit, GitLogOpts, and parseGitLog.
  • packages/js-sdk/tests/sandbox/git/log.test.ts:
    • Added Vitest unit test suite covering empty logs, formatted output parsing, runtime argument validation (maxCount <= 0), and commands.run argument formatting.
  • .changeset/git-log-history.md:
    • Included a minor changeset for e2b.

Pre-flight Checklist

  • pnpm run format — prettier check clean on modified files
  • pnpm run lintoxlint clean (0 errors, 0 warnings across 141 files)
  • pnpm run typechecktsc --noEmit clean
  • Unit tests added & passing — vitest run tests/sandbox/git/log.test.ts (4/4 passed)
  • Changeset created — .changeset/git-log-history.md (e2b: minor)

@cla-bot

cla-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

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-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9c0e1d7

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

This PR includes changesets to release 1 package
Name Type
e2b Minor

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

@Rehansanjay

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Jul 16, 2026
@cla-bot

cla-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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[]> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +520 to +521
const result = await this.runGit(args, path, rest)
return parseGitLog(result.stdout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +513 to +517
if (maxCount !== undefined) {
if (maxCount <= 0) {
throw new InvalidArgumentError('maxCount must be a positive number.')
}
args.push('-n', maxCount.toString())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@mishushakov

Copy link
Copy Markdown
Member

We're not accepting git related contributions atm.

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.

2 participants