Files
pnpm/packages/git-utils/test/index.test.ts
2025-08-28 14:00:51 +02:00

40 lines
982 B
TypeScript

import { temporaryDirectory } from 'tempy'
import execa from 'execa'
import fs from 'fs'
import path from 'path'
import { getCurrentBranch, isGitRepo, isWorkingTreeClean } from '@pnpm/git-utils'
test('isGitRepo', async () => {
const tempDir = temporaryDirectory()
process.chdir(tempDir)
await expect(isGitRepo()).resolves.toBe(false)
await execa('git', ['init'])
await expect(isGitRepo()).resolves.toBe(true)
})
test('getCurrentBranch', async () => {
const tempDir = temporaryDirectory()
process.chdir(tempDir)
await execa('git', ['init'])
await execa('git', ['checkout', '-b', 'foo'])
await expect(getCurrentBranch()).resolves.toBe('foo')
})
test('isWorkingTreeClean', async () => {
const tempDir = temporaryDirectory()
process.chdir(tempDir)
await execa('git', ['init'])
await expect(isWorkingTreeClean()).resolves.toBe(true)
fs.writeFileSync(path.join(tempDir, 'foo'), 'foo')
await expect(isWorkingTreeClean()).resolves.toBe(false)
})