From 967f99abc0b2a5a1e55bbca2c1e1e012fd5c157e Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 20 Jul 2018 10:33:18 -0400 Subject: [PATCH] fix(create): fix force git init --- packages/@vue/cli/bin/vue.js | 9 +++++++-- packages/@vue/cli/lib/Creator.js | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/@vue/cli/bin/vue.js b/packages/@vue/cli/bin/vue.js index 1c1fc6bfd0..2f5a9866aa 100755 --- a/packages/@vue/cli/bin/vue.js +++ b/packages/@vue/cli/bin/vue.js @@ -49,13 +49,18 @@ program .option('-i, --inlinePreset ', 'Skip prompts and use inline JSON string as preset') .option('-m, --packageManager ', 'Use specified npm client when installing dependencies') .option('-r, --registry ', '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 diff --git a/packages/@vue/cli/lib/Creator.js b/packages/@vue/cli/lib/Creator.js index 8cfea215c5..84a4a4ec5b 100644 --- a/packages/@vue/cli/lib/Creator.js +++ b/packages/@vue/cli/lib/Creator.js @@ -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) } }