Skip to content

Instantly share code, notes, and snippets.

@kkemple
Created July 15, 2015 14:27
Show Gist options
  • Save kkemple/ffbdb9fe6dbcc2ea13a3 to your computer and use it in GitHub Desktop.
Save kkemple/ffbdb9fe6dbcc2ea13a3 to your computer and use it in GitHub Desktop.
parse output of `git status --porcelain` command
'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