Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

2.4 KB
Raw Blame
import { expect } from 'vitest'

import { gitTest } from '../../setup.js'
import {
  cleanupBaseDir,
  createBaseDir,
  createRepoWithCommit,
} from './helpers.js'

gitTest('git branches lists current and feature', async ({ sandbox }) => {
  const baseDir = await createBaseDir(sandbox)

  try {
    const repoPath = await createRepoWithCommit(sandbox, baseDir)
    await sandbox.commands.run(`git -C "${repoPath}" branch feature`)

    const branches = await sandbox.git.branches(repoPath)
    expect(branches.currentBranch).toBe('main')
    expect(branches.branches).toContain('main')
    expect(branches.branches).toContain('feature')
  } finally {
    await cleanupBaseDir(sandbox, baseDir)
  }
})

gitTest('git checkoutBranch switches branch', async ({ sandbox }) => {
  const baseDir = await createBaseDir(sandbox)

  try {
    const repoPath = await createRepoWithCommit(sandbox, baseDir)
    await sandbox.commands.run(`git -C "${repoPath}" branch feature`)

    await sandbox.git.checkoutBranch(repoPath, 'feature')

    const head = (
      await sandbox.commands.run(
        `git -C "${repoPath}" rev-parse --abbrev-ref HEAD`
      )
    ).stdout.trim()
    expect(head).toBe('feature')
  } finally {
    await cleanupBaseDir(sandbox, baseDir)
  }
})

gitTest(
  'git createBranch creates and checks out branch',
  async ({ sandbox }) => {
    const baseDir = await createBaseDir(sandbox)

    try {
      const repoPath = await createRepoWithCommit(sandbox, baseDir)
      await sandbox.git.createBranch(repoPath, 'feature')

      const branches = await sandbox.git.branches(repoPath)
      expect(branches.branches).toContain('feature')
      expect(branches.currentBranch).toBe('feature')
    } finally {
      await cleanupBaseDir(sandbox, baseDir)
    }
  }
)

gitTest('git deleteBranch removes branch', async ({ sandbox }) => {
  const baseDir = await createBaseDir(sandbox)

  try {
    const repoPath = await createRepoWithCommit(sandbox, baseDir)
    await sandbox.commands.run(`git -C "${repoPath}" branch feature`)

    await sandbox.git.deleteBranch(repoPath, 'feature')

    const branch = (
      await sandbox.commands.run(`git -C "${repoPath}" branch --list feature`)
    ).stdout.trim()
    const branches = await sandbox.git.branches(repoPath)
    expect(branch).toBe('')
    expect(branches.branches).not.toContain('feature')
  } finally {
    await cleanupBaseDir(sandbox, baseDir)
  }
})