Skip to content

Commit 967f99a

Browse files
committed
fix(create): fix force git init
1 parent dcf9931 commit 967f99a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/@vue/cli/bin/vue.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ program
4949
.option('-i, --inlinePreset <json>', 'Skip prompts and use inline JSON string as preset')
5050
.option('-m, --packageManager <command>', 'Use specified npm client when installing dependencies')
5151
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
52-
.option('-g, --git [message]', 'Force git initialization with optional initial commit message')
52+
.option('-g, --git [message]', 'Force git initialization with initial commit message')
5353
.option('-n, --no-git', 'Skip git initialization')
5454
.option('-f, --force', 'Overwrite target directory if it exists')
5555
.option('-c, --clone', 'Use git clone when fetching remote preset')
5656
.option('-x, --proxy', 'Use specified proxy when creating project')
5757
.action((name, cmd) => {
58-
require('../lib/create')(name, cleanArgs(cmd))
58+
const options = cleanArgs(cmd)
59+
// --no-git makes commander to default git to true
60+
if (process.argv.includes('-g') || process.argv.includes('--git')) {
61+
options.forceGit = true
62+
}
63+
require('../lib/create')(name, options)
5964
})
6065

6166
program

packages/@vue/cli/lib/Creator.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,15 @@ module.exports = class Creator extends EventEmitter {
440440
if (!hasGit()) {
441441
return false
442442
}
443-
if (typeof cliOptions.git !== 'undefined') {
444-
return cliOptions.git !== 'false' && cliOptions.git !== false
443+
// --git
444+
if (cliOptions.forceGit) {
445+
return true
445446
}
446-
447+
// --no-git
448+
if (cliOptions.git === false || cliOptions.git === 'false') {
449+
return false
450+
}
451+
// default: true unless already in a git repo
447452
return !hasProjectGit(this.context)
448453
}
449454
}

0 commit comments

Comments
 (0)