Skip to content

Commit

Permalink
fix(windows): fix file name processing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
neikvon committed Aug 13, 2018
1 parent 6f6f06e commit e3c50c9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/^...//`
Expand All @@ -33,22 +33,23 @@ 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))
}
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
Expand All @@ -68,26 +69,26 @@ 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

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',
Expand Down

0 comments on commit e3c50c9

Please sign in to comment.