# staged-git-files

> get a list of staged git files and their status

Latest version **1.3.0** (published 2022-02-03) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install staged-git-files
pnpm add staged-git-files
yarn add staged-git-files
bun add staged-git-files
```

Provides the command `sgf`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2022-02-03 |
| First published | 2013-10-17 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Matthew Chase Whittemore |
| Maintainers | mcwhittemore |
| Keywords | git, pre-commit, post-commit, hooks |

## Links

- npm: https://www.npmjs.com/package/staged-git-files
- Repository: https://github.com/mcwhittemore/staged-git-files
- Homepage: https://github.com/mcwhittemore/staged-git-files#readme
- Issues: https://github.com/mcwhittemore/staged-git-files/issues
- npm.io page: https://npm.io/package/staged-git-files

## Recent versions

- 1.3.0 (latest) — 2022-02-03
- 1.2.0 — 2019-05-07
- 1.1.2 — 2018-10-29
- 1.1.1 — 2018-03-30
- 1.1.0 — 2018-02-20
- 1.0.0 — 2018-02-15
- 0.0.4 — 2015-01-18
- 0.0.3 — 2014-11-16
- 0.0.2 — 2013-10-18
- 0.0.1 — 2013-10-17

## README

# Staged Git Files

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

[![Build Status](https://travis-ci.org/mcwhittemore/staged-git-files.svg?branch=master)](https://travis-ci.org/mcwhittemore/staged-git-files)

## Usage

`npm install staged-git-files`


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

**Example Results**

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

## Usage as a cli

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

## API

### sgf(filter, callback)

Get a list of staged git files

* options:
  * filter: string of git status codes. No spaces
  * relative: boolean, tells [diff to run in relative mode](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---relativeltpathgt)
* callback:
	* err: the error
	* results: file object array.

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

```javascript
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](http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback) 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)

---
_Source: https://npm.io/package/staged-git-files · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
