1 | import { execGit } from './execGit.js'
|
2 |
|
3 | export const getStagedFiles = async (options) => {
|
4 | try {
|
5 | // Docs for --diff-filter option: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203
|
6 | // Docs for -z option: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--z
|
7 | const lines = await execGit(
|
8 | ['diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z'],
|
9 | options
|
10 | )
|
11 | // With `-z`, git prints `fileA\u0000fileB\u0000fileC\u0000` so we need to remove the last occurrence of `\u0000` before splitting
|
12 | // eslint-disable-next-line no-control-regex
|
13 | return lines ? lines.replace(/\u0000$/, '').split('\u0000') : []
|
14 | } catch {
|
15 | return null
|
16 | }
|
17 | }
|