confirmIfGitDirty.js 792 B

12345678910111213141516171819202122232425262728293031323334
  1. const inquirer = require('inquirer')
  2. const {
  3. execa,
  4. warn,
  5. hasProjectGit
  6. } = require('@vue/cli-shared-utils')
  7. module.exports = async function confirmIfGitDirty (context) {
  8. if (process.env.VUE_CLI_SKIP_DIRTY_GIT_PROMPT || process.env.VUE_CLI_API_MODE) {
  9. return true
  10. }
  11. process.env.VUE_CLI_SKIP_DIRTY_GIT_PROMPT = true
  12. if (!hasProjectGit(context)) {
  13. return true
  14. }
  15. const { stdout } = await execa('git', ['status', '--porcelain'], { cwd: context })
  16. if (!stdout) {
  17. return true
  18. }
  19. warn(`There are uncommited changes in the current repository, it's recommended to commit or stash them first.`)
  20. const { ok } = await inquirer.prompt([
  21. {
  22. name: 'ok',
  23. type: 'confirm',
  24. message: 'Still proceed?',
  25. default: false
  26. }
  27. ])
  28. return ok
  29. }