1 | import path from 'node:path'
|
2 |
|
3 | import normalize from 'normalize-path'
|
4 |
|
5 | import { execGit } from './execGit.js'
|
6 | import { getDiffCommand } from './getDiffCommand.js'
|
7 | import { parseGitZOutput } from './parseGitZOutput.js'
|
8 |
|
9 | export 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 | }
|