Skip to content

Commit

Permalink
Simplify by finding nearest parent directory with .git
Browse files Browse the repository at this point in the history
  • Loading branch information
robfentress committed Aug 11, 2016
1 parent 9ebe751 commit 9114d83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

var getHook = require('./lib/get-hook');

module.exports = function (gulp, dir) {
module.exports = function (gulp) {
return {
stream: function (name, options) {
var hook = getHook(name, dir);
var hook = getHook(name);

if (!hook.stream) {
throw new Error('Hook not streamable: ' + name);
Expand All @@ -14,7 +14,7 @@ module.exports = function (gulp, dir) {
return hook.stream(gulp, options);
},
src: function (name, fn) {
var hook = getHook(name, dir);
var hook = getHook(name);

if (fn && typeof fn === 'function') {
if (hook.extra) {
Expand Down
23 changes: 14 additions & 9 deletions lib/get-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ var execSync = require('shelljs').exec;
var stripBom = require('strip-bom');
var map = require('map-stream');
var hookArgs = process.env.HOOK_ARGS ? process.env.HOOK_ARGS.split('\u263a') : [];
var dir = "./";
var findParentDir = require('find-parent-dir');
var dir;
try {
dir = findParentDir.sync(__dirname, '.git');
} catch(err) {
console.error('error', err);
}

function getIndexed() {
return _.compact(execSync('(cd ' + dir + ' && git diff --cached --name-only --diff-filter=ACM)', {
silent: true
}).output.split('\n'));
return _.compact(execSync('(cd ' + dir + ' && git diff --cached --name-only --diff-filter=ACM)', {
silent: true
}).output.split('\n'));
}

function streamFromIndexed(gulp, options) {
Expand All @@ -19,9 +25,9 @@ function streamFromIndexed(gulp, options) {
var hash = execSync('git ls-files -s ' + file.path, {
silent: true
}).output.split(' ')[1];
var hash = execSync('(cd ' + dir + 'g && it ls-files -s ' + file.path + ')', {
silent: true
}).output.split(' ')[1];
var hash = execSync('(cd ' + dir + 'g && it ls-files -s ' + file.path + ')', {
silent: true
}).output.split(' ')[1];

if (!hash || !hash.length) {
// untracked file, use working copy
Expand Down Expand Up @@ -124,8 +130,7 @@ var hooks = [
}
];

function getHookObj(name, root) {
if (root !== undefined) { dir = root; }
function getHookObj(name) {
var hook = _.findWhere(hooks, { name: name });

if (!hook) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"chai": "^3.5.0",
"find-parent-dir": "^0.3.0",
"gulp": "^3.9.1",
"gulp-filter": "^4.0.0",
"gulp-istanbul": "^1.0.0",
Expand Down

0 comments on commit 9114d83

Please sign in to comment.