const fs = require('fs-extra')
const git = require('simple-git/promise')
const throwError = require('./throwError')


const isEmpty = async path => {
  const files = await fs.readdir(path)
  if (files.length) return false

  return true
}

const reminder = [
  'This command may cause some files to be overwritten',
  "If you're sure you want to run this command, rerun it with --force.",
].join('\n')
module.exports = async path => {
  if (!(await isEmpty(path))) {
    throwError([
      'The project directory is not a git repository and is a non-empty folder.',
      reminder,
    ].join('\n'))
  } else if (await git(path).checkIsRepo()) {
    throwError([
      'Git working directory not clean',
      reminder,
    ].join('\n'))
  }
}

@@ -395,16 +395,129 @@
 n('%5Cn')%0A
+%0Aconst isWorkDirClean = async path =%3E %7B%0A  const %7B files %7D =  await git(path).status()%0A%0A  return !files.length%0A%7D%0A%0A
 module.e
@@ -555,16 +555,52 @@
 !(await 
+git(path).checkIsRepo()) && !(await 
 isEmpty(
@@ -758,37 +758,37 @@
  if 
+(!
 (await 
-git(path).checkIsRepo(
+isWorkDirClean(path)
 )) %7B

check if the working directory is clean