Get the change between index (or staging-area) and working directory of a
git
repository
Think of git status
or git status --porcelain
, but returns a ready-to-consume result.
- Maintained
- Accepts simple wildcard matching patterns
- Promise API
- Ability to get specific results based on status codes
- Knows which files are partially/fully-staged
npm install g-status
$ git status --porcelain
A .travis.yml # fully-staged
MM index.js # partially-staged
M readme.md # unstaged
const gStatus = require('g-status');
gStatus().then(res => {
console.log(res);
/*
[
{ path: '.travis.yml', index: 'A', workingTree: ' ' },
{ path: 'index.js', index: 'M', workingTree: 'M' },
{ path: 'readme.md', index: ' ', workingTree: 'M' }
]
*/
});
gStatus({ path: ['!*.js', '!*.md'] }).then(res => {
console.log(res);
//=> [{ path: '.travis.yml', index: 'A', workingTree: ' ' }]
});
// Files marked as `Modified` or `Added` in the staging area,
gStatus({ index: 'MA' }).then(res => {
console.log(res);
/*
[
{ path: '.travis.yml', index: 'A', workingTree: ' ' },
{ path: 'index.js', index: 'M', workingTree: 'M' },
]
*/
});
// Files that arenʼt changed in the working tree
gStatus({ workingTree: ' ' }).then(res => {
console.log(res);
//=> [{ path: '.travis.yml', index: 'A', workingTree: ' ' }]
});
// Files that are marked as `Modified` both in staging area and working tree
gStatus({ index: 'M', workingTree: 'M' }).then(res => {
console.log(res);
//=> [{ path: 'index.js', index: 'M', workingTree: 'M' }]
});
See the tests for more usage examples and expected matches.
Returns Promise<{ path: string, index: string, workingTree: string }[]>
.
Type: Object
Type: string
Default: process.cwd()
Current working directory.
Type: string
| string[]
Default: *
Use *
to match zero or more characters. A pattern starting with !
will be negated.
Type: string
Default: *
String of git
status codes of the index/staging-area, See Short Format.
One difference is that *
will match all value here.
Type: string
Default: *
String of git
status codes of the working tree, See Short Format.
One difference is that *
will match all value here.
- simple-git – Simple git interface for Node.js
- staged-git-files – Abandoned, the latest commit was 3 years ago
MIT © Lufty Wiranda