Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

staged-git-files

mcwhittemore854kBSD-2-Clause1.3.0

get a list of staged git files and their status

git, pre-commit, post-commit, hooks

readme

Staged Git Files

This module returns an array of staged files and their status acording to git.

Build Status

Usage

npm install staged-git-files

var sgf = require("staged-git-files");
sgf(function(err, results){
    //WHAT EVER YOU SO PLEASE
});

Example Results

[
    {
        "filename": "package.json",
        "status": "Added"
    },
    {
        "filename": "readme.md",
        "status": "Modified"
    },
    {
        "filename": "index.js",
        "status": "Renamed"
    }
]

Usage as a cli

$ sgf
Added package.json
Modified readme.md
Renamed index.js

API

sgf(filter, callback)

Get a list of staged git files

  • options:
  • callback:
    • err: the error
    • results: file object array.

If you omit a callback sgf will return a promise. How to use with async/await:

async function main () {
    const stagedFiles = await sgf();
}

main();

sgf.getHead(callback)

Get head that will be used in the diff to ID which files are waiting to be staged.

  • callback
    • err: the error
    • head: the git commit id which is aliased to head.

sgf.readFile(filename, [options], callback)

This is a proxy for fs.readFile with one change. The filename will be relative to the sgf.cwd

sgf.debug

Boolean that flips logging on and off. By default this is false. If true, all git commands will be console logged.

sgf.includeContent

If true, include content will add a content or err param to the file object.

  • Default Value: false
  • Content Param: the content of the file staged
  • Err Param: the error message received while trying to read the file.

sgf.cwd

The current working directory. AKA: where the .git folder you care about is.

Default Value: is equal to process.cwd() of your app.g

Statuses

SGF-Status (git status code)

  • Added (A)
  • Copied (C)
  • Deleted (D)
  • Modified (M)
  • Renamed (R)
  • Type-Change (T) [i.e. regular file, symlink, submodule, etc.]
  • Unmerged (U)
  • Unknown (X)

changelog

Change Log

1.3.0

1.2.0

1.1.1

  • Fix bug where chinese files names were returned as unicode ids #15 by imcuttle

1.1.0

  • Provide a binary called sgf #11
  • Improve git request to not include slow flags when the results of those flags aren't needed #8 by twhitbeck.

1.0.0

0.0.4

  • Improve tests to cover many more files #3.

0.0.3

0.0.2

  • sgf.includeContent added. Now it is possible to also get the file content

0.0.1

  • The mvp