Skip to content

🏺Parse git status --porcelain output with a pleasure.

Notifications You must be signed in to change notification settings

putoutjs/git-status-porcelain

Repository files navigation

Porcelain License NPM version Build Status Coverage

Parse git status --porcelain output with a pleasure.

Install

npm i @putout/git-status-porcelain

How to use?

porcelain can be used in simpified mode, when you just need names of modified files (added, deleted, works as well):

const porcelain = require('@putout/git-status-porcelain');

porcelain({
    modified: true,
    untracked: true,
});

// returns
[
    'README.md',
    '1.js',
];

But you can break porcelain into pieces as well 😉:

const porcelain = require('@putout/git-status-porcelain');

const {
    run,
    parse,
    pick,
    getNames,
} = porcelain;

// run 'git status --porcelain'
const stdout = run();

// returns
' M README.md\n?? 1.js\n';

const files = parse(stdout);

// returns
[{
    name: 'README.md',
    mode: ' M ',
}, {
    name: '1.js',
    mode: '?',
}];

const modifiedFiles = pick(files, {
    modified: true,
    untracked: false,
    deleted: false,
    added: false,
    renamed: false,
    unstaged: false,
});

// returns
[{
    name: 'README.md',
    mode: ' M ',
}];

getNames(modifiedFiles);
// returns
['README.md'];

License

MIT