From e3c50c966f519de746206a12f223e8561c739a29 Mon Sep 17 00:00:00 2001 From: shaw Date: Mon, 13 Aug 2018 15:05:43 +0800 Subject: [PATCH] fix(windows): fix file name processing problems --- lib/git.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/git.js b/lib/git.js index 346b181..447d6dc 100644 --- a/lib/git.js +++ b/lib/git.js @@ -5,7 +5,7 @@ const inquirer = require('inquirer') const isWin = process.platform === 'win32' const root = process.cwd() -async function isGitRepo (dir) { +async function isGitRepo(dir) { try { const ret = await execa.shell('git rev-parse --git-dir', { cwd: dir @@ -16,14 +16,14 @@ async function isGitRepo (dir) { } } -function showStatus (filepath) { +function showStatus(filepath) { return execa.shell(`git status --short ${filepath || ''}`, { cwd: root, stdio: 'inherit' }) } -async function getStatus (filepath, nolog) { +async function getStatus(filepath, nolog) { const cmd = isWin ? `git status ${filepath || ''} --porcelain` : `git status ${filepath || ''} --porcelain | sed s/^...//` @@ -33,9 +33,9 @@ async function getStatus (filepath, nolog) { const stdout = await getStream(stream) - let ret = stdout.trim() + let ret = stdout - if (ret && !nolog) { + if (ret.trim() && !nolog) { ret = ret.split('\n').filter(p => p.trim()) if (isWin) { ret = ret.map(i => i.slice(3)) @@ -43,12 +43,13 @@ async function getStatus (filepath, nolog) { console.log() ctx.logger.info('current status:') await showStatus() + return ret } - return ret + return ret.trim() } // show only staged files -async function getStaged () { +async function getStaged() { // git diff --staged // git diff --cached --name-only // git diff --name-only --cached | xargs @@ -68,7 +69,7 @@ async function getStaged () { // This will list out your local comment history (not yet pushed) with corresponding message // git reflog -async function getUnpushedCommits () { +async function getUnpushedCommits() { const stream = execa.shell('git cherry -v', { cwd: root }).stdout @@ -76,18 +77,18 @@ async function getUnpushedCommits () { return getStream(stream) } -async function push (args) { +async function push(args) { return execa.shell(`git push ${args || ''}`, { cwd: root, stdio: 'inherit' }) } -function isClean () { +function isClean() { return getStatus('', true) } -async function gitInit () { +async function gitInit() { const answer = await inquirer.prompt({ type: 'confirm', name: 'initNow',