https://github.com/luftywiranda13/g-status
Get the change between index (or staging-area) and working tree of a `git` repository
https://github.com/luftywiranda13/g-status
git parse staged staging staging-area status working-directory working-tree
Last synced: 16 days ago
JSON representation
Get the change between index (or staging-area) and working tree of a `git` repository
- Host: GitHub
- URL: https://github.com/luftywiranda13/g-status
- Owner: luftywiranda13
- License: mit
- Created: 2018-01-21T13:54:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T09:19:48.000Z (almost 5 years ago)
- Last Synced: 2025-03-25T21:12:26.978Z (about 1 month ago)
- Topics: git, parse, staged, staging, staging-area, status, working-directory, working-tree
- Language: JavaScript
- Homepage:
- Size: 153 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# g-status
> Get the change between index (or staging-area) and working directory of a `git` repository
[](https://www.npmjs.com/package/g-status)
[](https://npm-stat.com/charts.html?package=g-status&from=2016-04-01)
[](https://travis-ci.org/luftywiranda13/g-status)
[](https://codecov.io/gh/luftywiranda13/g-status)Think of `git status` or `git status --porcelain`, but returns a _ready-to-consume_ result.
## Why
* Maintained
* Accepts simple [wildcard matching](https://github.com/sindresorhus/matcher) patterns
* Promise API
* Ability to get specific results based on status codes
* Knows which files are partially/fully-staged## Installation
```sh
npm install g-status
```## Usage
```sh
$ git status --porcelainA .travis.yml # fully-staged
MM index.js # partially-staged
M readme.md # unstaged
``````js
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](https://github.com/luftywiranda13/g-status/blob/master/test.js) for more usage examples and expected matches.
## API
### gStatus([options])
Returns `Promise<{ path: string, index: string, workingTree: string }[]>`.
#### options
Type: `Object`
##### cwd
Type: `string`
Default: `process.cwd()`Current working directory.
##### path
Type: `string` | `string[]`
Default: `*`Use `*` to match zero or more characters. A pattern starting with `!` will be negated.
##### index
Type: `string`
Default: `*`String of `git` status codes of the index/staging-area, See [Short Format](https://git-scm.com/docs/git-status#_short_format).
One difference is that `*` will match all value here.##### workingTree
Type: `string`
Default: `*`String of `git` status codes of the working tree, See [Short Format](https://git-scm.com/docs/git-status#_short_format).
One difference is that `*` will match all value here.## Related
* [simple-git](https://github.com/steveukx/git-js) – Simple git interface for Node.js
* [staged-git-files](https://github.com/mcwhittemore/staged-git-files) – Abandoned, the latest commit was 3 years ago## License
MIT © [Lufty Wiranda](https://www.luftywiranda.com)