0.3.0 • Published 6 years ago

git-parser v0.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

git-parser

Travis Coveralls branch license

Parse Git output

Install

$ npm install --save git-parser

Example

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

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

{
  "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