Skip to content

Commit

Permalink
fix(create): fix force git init
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 20, 2018
1 parent dcf9931 commit 967f99a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 967f99a

Please sign in to comment.