1 | import path from 'path'
|
2 |
|
3 | import normalize from 'normalize-path'
|
4 |
|
5 | import { execGit } from './execGit.js'
|
6 | import { parseGitZOutput } from './parseGitZOutput.js'
|
7 |
|
8 | export const getStagedFiles = async ({ cwd = process.cwd() } = {}) => {
|
9 | try {
|
10 |
|
11 |
|
12 | const lines = await execGit(['diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z'], {
|
13 | cwd,
|
14 | })
|
15 |
|
16 | if (!lines) return []
|
17 |
|
18 | return parseGitZOutput(lines).map((file) => normalize(path.resolve(cwd, file)))
|
19 | } catch {
|
20 | return null
|
21 | }
|
22 | }
|