1const git = require('@npmcli/git') 2const log = require('proc-log') 3 4// returns true if it's cool to do git stuff 5// throws if it's unclean, and not forced. 6module.exports = async opts => { 7 const { force } = opts 8 let hadError = false 9 const clean = await git.isClean(opts).catch(er => { 10 if (er.code === 'ENOGIT') { 11 log.warn( 12 'version', 13 'This is a Git checkout, but the git command was not found.', 14 'npm could not create a Git tag for this release!' 15 ) 16 hadError = true 17 // how can merges be real if our git isn't real? 18 return true 19 } else { 20 throw er 21 } 22 }) 23 24 if (!clean) { 25 if (!force) { 26 throw new Error('Git working directory not clean.') 27 } 28 log.warn('version', 'Git working directory not clean, proceeding forcefully.') 29 } 30 31 return !hadError 32} 33