Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
- code cleanup
- drops support for node@4
- updates license in package.json
- updates chalk@2.0.1 -> chalk@2.1.0
  • Loading branch information
gabrielcsapo committed Sep 9, 2017
1 parent 8c29b27 commit 2b6bb71
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 32 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
coverage
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ script:
- npm run coverage
- cat coverage/lcov.info | node-coverage-cli --url https://node-coverage-server.herokuapp.com
node_js:
- "4"
- "6"
- "8"
os:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.3.0 (09/09/2017)

- code cleanup
- drops support for node@4
- updates license in package.json
- updates `chalk@2.0.1` -> `chalk@2.1.0`

# 0.2.0 (07/13/2017)

- updates readme to include the ability to run as a custom git command
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# git-unstaged

[![Greenkeeper badge](https://badges.greenkeeper.io/gabrielcsapo/git-unstaged.svg)](https://greenkeeper.io/)

> Get all unstaged git repos in a folder
> 🎭 Get all unstaged git repos in a folder
[![Npm Version](https://img.shields.io/npm/v/git-unstaged.svg)](https://www.npmjs.com/package/git-unstaged)
[![Build Status](https://travis-ci.org/gabrielcsapo/git-unstaged.svg?branch=master)](https://travis-ci.org/gabrielcsapo/git-unstaged)
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [ ] remove sync operations
2 changes: 1 addition & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const chalk = require('chalk');
const program = require('commander');
const search = require('../lib/search').search;
const { search } = require('../lib/search');
const log = console.log; // eslint-disable-line

program
Expand Down
16 changes: 7 additions & 9 deletions lib/search.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const path = require('path');
const fs = require('fs');
const exec = require('child_process').execSync;
const { execSync } = require('child_process');

function getContents(directory) {
try {
const git = fs.statSync(path.resolve(directory, '.git'));
if(git.isDirectory()) {
return exec(' git status --porcelain --branch', {
return execSync('git status --porcelain --branch', {
cwd: path.resolve(directory)
}).toString('utf8');
}
} catch(ex) {
// noop
return;
}
}

Expand All @@ -22,9 +22,8 @@ function getDirectories(directory) {
}

function search(directory, depth, callback) {
const output = {};

const found = [[directory]];
let found = [[directory]];
let output = {};

for(var i = 0; i <= depth; i++) {
found[i].forEach((dir) => {
Expand All @@ -34,9 +33,7 @@ function search(directory, depth, callback) {
});
}

const directories = [].concat.apply([], found);

directories.forEach((dir) => {
[].concat.apply([], found).forEach((dir) => {
const contents = getContents(path.resolve(directory, dir));
if(contents) {
output[path.resolve(directory, dir)] = contents;
Expand All @@ -47,5 +44,6 @@ function search(directory, depth, callback) {

module.exports = {
search,
getDirectories,
getContents
};
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "git-unstaged",
"version": "0.2.0",
"description": "Get all unstaged git repos in a folder",
"description": "🎭 Get all unstaged git repos in a folder",
"author": "Gabriel J. Csapo <gabecsapo@gmail.com>",
"license": "MIT",
"bugs": {
Expand All @@ -15,6 +15,7 @@
"keywords": [
"git"
],
"license": "MIT",
"main": "index.js",
"bin": {
"git-unstaged": "./bin/index.js"
Expand All @@ -25,12 +26,12 @@
"coverage": "tap test/*.js --coverage --coverage-report=lcov"
},
"dependencies": {
"chalk": "^2.0.1",
"chalk": "^2.1.0",
"commander": "^2.11.0"
},
"devDependencies": {
"eslint": "^4.1.1",
"tap": "^10.7.0",
"tape": "^4.7.0"
"eslint": "^4.6.1",
"tap": "^10.7.2",
"tape": "^4.8.0"
}
}
40 changes: 27 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,45 @@ const test = require('tape');
const path = require('path');
const exec = require('child_process').exec;

const search = require('../lib/search').search;
const { search, getDirectories, getContents } = require('../lib/search');

const fixturesDirectory = path.resolve(__dirname, 'fixtures');

test('git-unstaged', (t) => {
const fixturesDirectory = path.resolve(__dirname, 'fixtures');
t.plan(3);

t.test('create random git repos with content in them', (t) => {
t.test('runs search in new directory', (t) => {
exec('mkdir test1 && cd test1 && git init && cat "hello world" > t.txt', {
cwd: fixturesDirectory
});
t.end();
setTimeout(() => {
search(fixturesDirectory, 1, (c) => {
t.equal(c[path.resolve(fixturesDirectory, 'test1')], "## Initial commit on master\n?? t.txt\n");
exec('rm -r ' + path.resolve(__dirname, 'fixtures', 'test1'), () => {
t.end();
});
});
}, 1000);
});

t.test('runs git-unstaged in test directory', (t) => {
t.test('runs getContents in new directory', (t) => {
exec('mkdir test1 && cd test1 && git init && cat "hello world" > t.txt', {
cwd: fixturesDirectory
});
setTimeout(() => {
search(fixturesDirectory, 1, (c) => {
t.equal(c[path.resolve(fixturesDirectory, 'test1')], "## Initial commit on master\n?? t.txt\n");
t.end();
});
const contents = getContents(path.resolve(fixturesDirectory, 'test1'));
t.equal(contents, '## Initial commit on master\n?? t.txt\n')
exec('rm -r ' + path.resolve(__dirname, 'fixtures', 'test1'), () => {
t.end();
});
}, 1000);
});

t.test('removes fixtures directory', (t) => {
exec('rm -r ' + path.resolve(__dirname, 'fixtures', 'test1'), () => {
t.end();
});
t.test('return fixtures directory', (t) => {
const directories = getDirectories(__dirname);
t.equal(directories.length, 1);
t.equal(directories[0].substring(directories[0].lastIndexOf('/') + 1, directories[0].length), 'fixtures');
t.end();
});

});

0 comments on commit 2b6bb71

Please sign in to comment.