Skip to content

Commit 2d1ff28

Browse files
committed
🎉 Initial commit
0 parents  commit 2d1ff28

11 files changed

Lines changed: 4045 additions & 0 deletions

File tree

‎.babelrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env"]
3+
}

‎.eslintrc.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "airbnb-base",
3+
"plugins": [
4+
"import"
5+
]
6+
}

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
build.js
3+
.nyc_output
4+
npm-debug.log
5+
coverage

‎.npmignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
index.js
2+
.nyc_output
3+
npm-debug.log
4+
coverage

‎.travis.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
sudo: true
3+
dist: trusty
4+
node_js:
5+
- "4"
6+
- "6"
7+
install:
8+
- npm i -g npm
9+
- npm install
10+
script: npm test
11+
notifications:
12+
email:
13+
on_failure: change
14+
after_success:
15+
- npm run coveralls

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Jan Peer Stöcklmair
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# is-git-added
2+
3+
[![Build Status](https://travis-ci.org/JPeer264/node-is-git-added.svg?branch=master)](https://travis-ci.org/JPeer264/node-is-git-added) [![Coverage Status](https://coveralls.io/repos/github/JPeer264/node-is-git-added/badge.svg?branch=master)](https://coveralls.io/github/JPeer264/node-is-git-added?branch=master)
4+
5+
Checks synchronously if files are added in a git repository
6+
7+
## Installation
8+
9+
```sh
10+
$ npm i is-git-added --save
11+
```
12+
or
13+
```sh
14+
$ yarn add is-git-added
15+
```
16+
17+
## Usage
18+
19+
- `false`: Nothing is added/in the HEAD, or it is no git repository
20+
- `true`: Changes are ready to commit. Files are added.
21+
22+
```js
23+
const isGitAdded = require('is-git-added');
24+
25+
isGitAdded(); // true or false of process.cwd()
26+
isGitAdded('any/git/repo'); // true or false
27+
```
28+
29+
## LICENSE
30+
31+
MIT © [Jan Peer Stöcklmair](https://www.jpeer.at)

‎index.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import execa from 'execa';
2+
import isGit from 'is-git-repository';
3+
4+
const cwd = process.cwd();
5+
6+
const isGitAdded = (altPath = cwd) => {
7+
if (!isGit(altPath)) {
8+
return false;
9+
}
10+
11+
try {
12+
execa.shellSync(`(cd ${altPath} ; git diff --cached --exit-code)`);
13+
14+
return false;
15+
} catch (e) {
16+
return true;
17+
}
18+
};
19+
20+
export default isGitAdded;

‎package.json‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "is-git-added",
3+
"version": "1.0.0",
4+
"description": "A tool to check if files are added in a git repository",
5+
"main": "build.js",
6+
"scripts": {
7+
"pretest": "npm run lint",
8+
"test": "ava",
9+
"lint": "eslint index.js",
10+
"coveralls": "nyc report --reporter=text-lcov | coveralls",
11+
"prepublish": "npm run babel",
12+
"babel": "babel index.js -o build.js",
13+
"prepush": "npm test"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/JPeer264/node-is-git-added.git"
18+
},
19+
"keywords": [
20+
"is",
21+
"git",
22+
"added",
23+
"HEAD",
24+
"repo",
25+
"is-git",
26+
"exists"
27+
],
28+
"author": "Jan Peer Stöcklmair",
29+
"license": "MIT",
30+
"bugs": {
31+
"url": "https://github.com/JPeer264/node-is-git-added/issues"
32+
},
33+
"ava": {
34+
"require": "babel-register",
35+
"babel": "inherit"
36+
},
37+
"nyc": {
38+
"exclude": [
39+
"build.js"
40+
]
41+
},
42+
"homepage": "https://github.com/JPeer264/node-is-git-added#readme",
43+
"dependencies": {
44+
"execa": "^0.6.1",
45+
"is-git-repository": "^1.0.0"
46+
},
47+
"devDependencies": {
48+
"ava": "^0.18.2",
49+
"babel-cli": "^6.24.0",
50+
"babel-preset-env": "^1.2.2",
51+
"coveralls": "^2.12.0",
52+
"eslint": "^3.18.0",
53+
"eslint-config-airbnb-base": "^11.1.1",
54+
"eslint-plugin-import": "^2.2.0",
55+
"fs-extra": "^2.1.2",
56+
"husky": "^0.13.2",
57+
"nyc": "^10.1.2"
58+
}
59+
}

‎test.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { homedir } from 'os';
2+
import test from 'ava';
3+
import execa from 'execa';
4+
import fs from 'fs-extra';
5+
6+
import isGit from './index';
7+
8+
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
9+
10+
test.serial('check if something is added in process.cwd() - manipulated', (t) => {
11+
fs.writeFileSync(`${randomString}.js`, 'console.log();');
12+
execa.sync('git', ['add', `${randomString}.js`]);
13+
14+
t.true(isGit());
15+
16+
execa.sync('git', ['reset', 'HEAD', `${randomString}.js`]);
17+
fs.removeSync(`${randomString}.js`);
18+
});
19+
20+
test('check if something is added in process.cwd()', (t) => {
21+
t.false(isGit());
22+
});
23+
24+
test('check if something is added in users home', (t) => {
25+
t.false(isGit(homedir()));
26+
});

0 commit comments

Comments
 (0)