Skip to content

Commit

Permalink
Refactor: is-git-clean to is-git-dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 committed Apr 22, 2018
1 parent e545142 commit 6f475da
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# is-git-clean
# is-git-dirty

[![Build Status](https://travis-ci.org/JPeer264/node-is-git-clean.svg?branch=master)](https://travis-ci.org/JPeer264/node-is-git-clean)
[![Build status](https://ci.appveyor.com/api/projects/status/ehj6762gbj1e2qyc?svg=true)](https://ci.appveyor.com/project/JPeer264/node-is-git-clean)
[![Coverage Status](https://coveralls.io/repos/github/JPeer264/node-is-git-clean/badge.svg?branch=master)](https://coveralls.io/github/JPeer264/node-is-git-clean?branch=master)
[![Build Status](https://travis-ci.org/JPeer264/node-is-git-dirty.svg?branch=master)](https://travis-ci.org/JPeer264/node-is-git-dirty)
[![Build status](https://ci.appveyor.com/api/projects/status/ehj6762gbj1e2qyc?svg=true)](https://ci.appveyor.com/project/JPeer264/node-is-git-dirty)
[![Coverage Status](https://coveralls.io/repos/github/JPeer264/node-is-git-dirty/badge.svg?branch=master)](https://coveralls.io/github/JPeer264/node-is-git-dirty?branch=master)

Checks synchronously if the git repository is clean. This assumes that no files are added, untracked or modified.

## Installation

```sh
$ npm i is-git-clean --save
$ npm i is-git-dirty --save
```
or
```sh
$ yarn add is-git-clean
$ yarn add is-git-dirty
```

## Usage

Returns:
- `false`: Files are added, untracked, modified or the path is not a git repository
- `true`: No files are added, untracked or modified.
- `null`: Directory is not a git repository
- `true`: Files are added, untracked, modified
- `false`: No files are added, untracked or modified. Git is clean

```js
const isGitClean = require('is-git-clean');
const isGitDirty = require('is-git-dirty');

isGitClean(); // true or false of process.cwd()
isGitClean('any/git/repo'); // true or false
isGitDirty(); // true or false of process.cwd()
isGitDirty('any/git/repo'); // true or false
```

## LICENSE
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isGitClean = (altPath = cwd) => {
let stdout;

if (!isGit(altPath)) {
return false;
return null;
}

try {
Expand All @@ -18,9 +18,9 @@ const isGitClean = (altPath = cwd) => {
({ stdout } = execa.shellSync(`(cd ${altPath} ; git status --short)`));
}

return stdout.length <= 0;
return stdout.length > 0;
} catch (e) {
return false;
return null;
}
};

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "is-git-clean",
"name": "is-git-dirty",
"version": "0.0.0",
"description": "Check if a repository has no untracked or added files",
"description": "Check if a repository has untracked or added files",
"main": "build.js",
"scripts": {
"pretest": "npm run lint",
Expand All @@ -18,7 +18,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/JPeer264/node-is-git-clean.git"
"url": "git+https://github.com/JPeer264/node-is-git-dirty.git"
},
"keywords": [
"is",
Expand All @@ -33,7 +33,7 @@
"author": "Jan Peer Stöcklmair",
"license": "MIT",
"bugs": {
"url": "https://github.com/JPeer264/node-is-git-clean/issues"
"url": "https://github.com/JPeer264/node-is-git-dirty/issues"
},
"ava": {
"require": "babel-register",
Expand All @@ -48,7 +48,7 @@
"index.js"
]
},
"homepage": "https://github.com/JPeer264/node-is-git-clean#readme",
"homepage": "https://github.com/JPeer264/node-is-git-dirty#readme",
"dependencies": {
"execa": "^0.10.0",
"is-git-repository": "^1.1.1"
Expand Down
18 changes: 13 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import path from 'path';
import fs from 'fs-extra';
import { homedir } from 'os';

import isGitClean from './';

Expand All @@ -27,8 +28,15 @@ const isGitMacro = (t, dir, assert) => {
t.is(isClean, assert);
};

test(isGitMacro, 'clean', true);
test(isGitMacro, 'modified', false);
test(isGitMacro, 'added', false);
test(isGitMacro, 'untracked', false);
test(isGitMacro, 'notexisting', false);
isGitMacro.title = (providedTitle, dir) => `${providedTitle} ${dir}`;

test(isGitMacro, 'clean', false);
test(isGitMacro, 'modified', true);
test(isGitMacro, 'added', true);
test(isGitMacro, 'untracked', true);

test('non existing path', (t) => {
const isClean = isGitClean(homedir());

t.is(isClean, null);
});

0 comments on commit 6f475da

Please sign in to comment.