'use strict';

var _require = require('child_process'),
    execSync = _require.execSync;

module.exports = function changedGitFiles(opMode) {
  var getModifiedFilesInTreeCommand = 'git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD';

  if (opMode === 'checkout') {
    var params = process.env.GIT_PARAMS.split(' ');

    if (params[2] === '0') {
      // Exit early if this was only a file checkout, not a branch change ($3 == 1)
      return [];
    }
    getModifiedFilesInTreeCommand = 'git diff-tree -r --name-only --no-commit-id ' + params[0] + ' ' + params[1];
  }

  var sources = execSync(getModifiedFilesInTreeCommand, { encoding: 'utf-8' });
  return sources.split('\n');
};