e32a347d8eb75844a7904a57fe944b174c4b388e1016240c39798e057f0eec2bc38f2e7b20c51fed38fe41598b7a7d68c363c63dcef2b853a5916dd8719574 750 B

12345678910111213141516171819
  1. 'use strict'
  2. const execGit = require('./execGit')
  3. module.exports = async function getStagedFiles(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. }