Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/git-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ module.exports = {
/**
* Runs a git hook.
*
* @param {String} filename Path to git hook.
* @param {String} [arg] Git hook argument.
* @param {String} filename Path to git hook.
* @param {String[]} [args] Git hook arguments.
* @param {Function} callback
*/
run: function (filename, arg, callback) {
run: function (filename, args, callback) {
var hookName = path.basename(filename);
var hooksDirname = path.resolve(path.dirname(filename), '../../.githooks', hookName);

Expand All @@ -127,7 +127,7 @@ module.exports = {
return path.resolve(hooksDirname, hookName);
});
excludeIgnoredPaths(hooks, function (filteredHooks) {
runHooks(filteredHooks, [arg], callback);
runHooks(filteredHooks, args, callback);
});
} else {
callback(0);
Expand Down
2 changes: 1 addition & 1 deletion lib/hook-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ try {
* www
* node_modules
*/
require('%s/git-hooks').run(__filename, process.argv[2], function (code, error) {
require('%s/git-hooks').run(__filename, process.argv.slice(2), function (code, error) {
if (error) {
console.error('[GIT-HOOKS ERROR] ' + error.message);
}
Expand Down
25 changes: 16 additions & 9 deletions tests/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('git-hook runner', function () {
});

it('should works without hooks', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, null, function (code) {
gitHooks.run(PRECOMMIT_HOOK_PATH, [], function (code) {
code.should.equal(0);
done();
});
Expand All @@ -44,7 +44,7 @@ describe('git-hook runner', function () {
});

it('should return an error', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, null, function (code, error) {
gitHooks.run(PRECOMMIT_HOOK_PATH, [], function (code, error) {
code.should.equal(1);
error.should.be.ok;
done();
Expand All @@ -62,7 +62,7 @@ describe('git-hook runner', function () {
});

it('should run it one by one', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, null, function (code) {
gitHooks.run(PRECOMMIT_HOOK_PATH, [], function (code) {
code.should.equal(0);
hooks.forEach(function (name) {
var logFile = SANDBOX_PATH + name + '.log';
Expand All @@ -73,16 +73,23 @@ describe('git-hook runner', function () {
});
});

describe('and works without errors', function () {
describe('and work without errors', function () {
var logFile = SANDBOX_PATH + 'hello.log';
beforeEach(function () {
createHook(PROJECT_PRECOMMIT_HOOK + 'hello', 'echo Hello, world! > ' + logFile);
createHook(PROJECT_PRECOMMIT_HOOK + 'hello', 'echo "Hello, world! ${@:1}" > ' + logFile);
});

it('should pass all arguments to them', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, ['I', 'am', 'working', 'properly!'], function () {
fs.readFileSync(logFile).toString().should.equal('Hello, world! I am working properly!\n');
done();
});
});

it('should run a hook with success status', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, null, function (code) {
gitHooks.run(PRECOMMIT_HOOK_PATH, [], function (code) {
code.should.equal(0);
fs.readFileSync(logFile).toString().should.equal('Hello, world!\n');
fs.readFileSync(logFile).toString().should.equal('Hello, world! \n');
done();
});
});
Expand All @@ -94,7 +101,7 @@ describe('git-hook runner', function () {
});

it('should run a hook and return error', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, null, function (code) {
gitHooks.run(PRECOMMIT_HOOK_PATH, [], function (code) {
code.should.equal(255);
done();
});
Expand All @@ -112,7 +119,7 @@ describe('git-hook runner', function () {
});

it('should ignore file with wrong permissions in hooks directory', function (done) {
gitHooks.run(PRECOMMIT_HOOK_PATH, null, function (code) {
gitHooks.run(PRECOMMIT_HOOK_PATH, [], function (code) {
code.should.equal(0);
done();
});
Expand Down