Dismiss
  • Toggle Theme
  • View as Mobile

Get files changed from Git history

const execa = require('execa')

function getChangedFiles() {
  let data
  try {
    data = await execa.command('git diff --name-only')
  } catch (e) {
    console.log(e)
  }
  if (!data.stdout) {
    return
  }
  const changedFiles = data.stdout.split('\n').map((file) => {
    return {
      path: file,
      fullPath: path.resolve(file)
    }
  })
  console.log('changedFiles', changedFiles)
  return changedFiles
}

For a more robust module checkout run-if-diff