UNPKG

536 BJavaScriptView Raw
1import path from 'node:path'
2
3import normalize from 'normalize-path'
4
5import { execGit } from './execGit.js'
6import { getDiffCommand } from './getDiffCommand.js'
7import { parseGitZOutput } from './parseGitZOutput.js'
8
9export const getStagedFiles = async ({ cwd = process.cwd(), diff, diffFilter } = {}) => {
10 try {
11 const lines = await execGit(getDiffCommand(diff, diffFilter), { cwd })
12 if (!lines) return []
13
14 return parseGitZOutput(lines).map((file) => normalize(path.resolve(cwd, file)))
15 } catch {
16 return null
17 }
18}