Created
July 15, 2015 14:27
-
-
Save kkemple/ffbdb9fe6dbcc2ea13a3 to your computer and use it in GitHub Desktop.
parse output of `git status --porcelain` command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import forEach from 'lodash.foreach'; | |
const statusRegex = /^([AMRDC]|\?\?)\s+([\w\d\/\.\-_]+)/; | |
export default (output) => { | |
if (typeof output !== 'string') return; | |
let statuses = { | |
modified: [], | |
added: [], | |
deleted: [], | |
renamed: [], | |
copied: [], | |
untracked: [] | |
}; | |
const keys = { | |
'M': 'modified', | |
'A': 'added', | |
'D': 'deleted', | |
'R': 'renamed', | |
'C': 'copied', | |
'??': 'untracked' | |
}; | |
forEach(output.split('\n'), (status) => { | |
const statusParts = statusRegex.exec(status.trim()); | |
statuses[keys[statusParts[1]]].push(statusParts[2]); | |
}); | |
return statuses; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment