which.js 339 B

123456789101112131415161718
  1. const which = require('which')
  2. let gitPath
  3. try {
  4. gitPath = which.sync('git')
  5. } catch {
  6. // ignore errors
  7. }
  8. module.exports = (opts = {}) => {
  9. if (opts.git) {
  10. return opts.git
  11. }
  12. if (!gitPath || opts.git === false) {
  13. return Object.assign(new Error('No git binary found in $PATH'), { code: 'ENOGIT' })
  14. }
  15. return gitPath
  16. }