https://github.com/vutran/git-parser
↔️ Parse Git output
https://github.com/vutran/git-parser
git javascript node parser
Last synced: about 1 year ago
JSON representation
↔️ Parse Git output
- Host: GitHub
- URL: https://github.com/vutran/git-parser
- Owner: vutran
- License: mit
- Created: 2016-08-22T18:51:09.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-08-05T00:59:40.000Z (almost 8 years ago)
- Last Synced: 2025-04-10T22:18:04.828Z (about 1 year ago)
- Topics: git, javascript, node, parser
- Language: JavaScript
- Homepage:
- Size: 103 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# git-parser
[](https://travis-ci.org/vutran/git-parser) [](https://coveralls.io/github/vutran/git-parser) [](LICENSE)
> Parse Git output
## Install
```bash
$ npm install --save git-parser
```
## Example
```js
const { exec } = require('child_process');
const { parseDiff } = require('git-parser');
exec('git diff', (err, stdout, stderr) => {
// parse the output of "git diff"
const diffs = parseDiff(stdout);
// array of diff objects
console.log(diffs);
});
```
## API
### parseDiff(output)
Returns an array of changes between commits.
#### output
Type: `string`
The diff output string
### parseHunkHeader
Returns an array of hunk headers.
#### output
Type: `string`
The diff output string
### parseFileHeader
Returns an array of hunk headers.
#### output
Type: `string`
The diff output string
### parseStatus(output)
Returns an array of working files' status using `--porcelain` option
```js
const { exec } = require('child_process');
const { parseStatus } = require('git-parser');
exec('git status --porcelain', (err, stdout, stderr) => {
// parse the output of "git status --porcelain". works with --branch to get branch name
const statuses = parseStatus(stdout);
console.log(statuses);
});
```
#### output
Type: `object`
JSON Schema
```json
{
"type": "object",
"properties": {
"branch": {
"type": "string",
"description": "if no branch is in input, it will return 'default'"
},
"statuses": {
"type": "array",
"properties": {
"staged": {
"type": "boolean",
"description": "if false, it will be either unstaged or untracked (untracked would have a status of '??')"
},
"fileName": {
"type": "string"
},
"status": {
"type": "string",
"description": "Uppercase status code: M = modified, A = added, D = deleted, R = renamed, C = copied, ?? = untracked"
}
}
}
}
}
```
## License
MIT © [Vu Tran](https://github.com/vutran/)