fix(create): fix force git init

This commit is contained in:
Evan You
2018-07-20 10:33:18 -04:00
parent dcf9931809
commit 967f99abc0
2 changed files with 15 additions and 5 deletions

View File

@@ -49,13 +49,18 @@ program
.option('-i, --inlinePreset <json>', 'Skip prompts and use inline JSON string as preset')
.option('-m, --packageManager <command>', 'Use specified npm client when installing dependencies')
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
.option('-g, --git [message]', 'Force git initialization with optional initial commit message')
.option('-g, --git [message]', 'Force git initialization with initial commit message')
.option('-n, --no-git', 'Skip git initialization')
.option('-f, --force', 'Overwrite target directory if it exists')
.option('-c, --clone', 'Use git clone when fetching remote preset')
.option('-x, --proxy', 'Use specified proxy when creating project')
.action((name, cmd) => {
require('../lib/create')(name, cleanArgs(cmd))
const options = cleanArgs(cmd)
// --no-git makes commander to default git to true
if (process.argv.includes('-g') || process.argv.includes('--git')) {
options.forceGit = true
}
require('../lib/create')(name, options)
})
program

View File

@@ -440,10 +440,15 @@ module.exports = class Creator extends EventEmitter {
if (!hasGit()) {
return false
}
if (typeof cliOptions.git !== 'undefined') {
return cliOptions.git !== 'false' && cliOptions.git !== false
// --git
if (cliOptions.forceGit) {
return true
}
// --no-git
if (cliOptions.git === false || cliOptions.git === 'false') {
return false
}
// default: true unless already in a git repo
return !hasProjectGit(this.context)
}
}