Skip to content

armgit / E2B

Public Imported from GitHub
0

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

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

import { gitTest } from '../../setup.js'
import {
  AUTHOR_EMAIL,
  AUTHOR_NAME,
  cleanupBaseDir,
  createBaseDir,
  createRepo,
} from './helpers.js'

gitTest('git getConfig reads local config', async ({ sandbox }) => {
  const baseDir = await createBaseDir(sandbox)

  try {
    const repoPath = await createRepo(sandbox, baseDir)
    await sandbox.commands.run(
      `git -C "${repoPath}" config --local pull.rebase true`
    )

    const value = await sandbox.git.getConfig('pull.rebase', {
      scope: 'local',
      path: repoPath,
    })
    const commandValue = (
      await sandbox.commands.run(
        `git -C "${repoPath}" config --local --get pull.rebase`
      )
    ).stdout.trim()
    expect(value).toBe('true')
    expect(commandValue).toBe('true')
  } finally {
    await cleanupBaseDir(sandbox, baseDir)
  }
})

gitTest('git setConfig updates local config', async ({ sandbox }) => {
  const baseDir = await createBaseDir(sandbox)

  try {
    const repoPath = await createRepo(sandbox, baseDir)

    await sandbox.git.setConfig('pull.rebase', 'true', {
      scope: 'local',
      path: repoPath,
    })

    const value = (
      await sandbox.commands.run(
        `git -C "${repoPath}" config --local --get pull.rebase`
      )
    ).stdout.trim()
    const configuredValue = await sandbox.git.getConfig('pull.rebase', {
      scope: 'local',
      path: repoPath,
    })
    expect(value).toBe('true')
    expect(configuredValue).toBe('true')
  } finally {
    await cleanupBaseDir(sandbox, baseDir)
  }
})

gitTest('git configureUser sets global user config', async ({ sandbox }) => {
  await sandbox.git.configureUser(AUTHOR_NAME, AUTHOR_EMAIL)

  const name = (
    await sandbox.commands.run('git config --global --get user.name')
  ).stdout.trim()
  const email = (
    await sandbox.commands.run('git config --global --get user.email')
  ).stdout.trim()
  const configuredName = await sandbox.git.getConfig('user.name', {
    scope: 'global',
  })
  const configuredEmail = await sandbox.git.getConfig('user.email', {
    scope: 'global',
  })

  expect(name).toBe(AUTHOR_NAME)
  expect(email).toBe(AUTHOR_EMAIL)
  expect(configuredName).toBe(AUTHOR_NAME)
  expect(configuredEmail).toBe(AUTHOR_EMAIL)
})