Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmp files in hook's directory #12

Closed
nik-kor opened this issue Jan 30, 2016 · 8 comments
Closed

tmp files in hook's directory #12

nik-kor opened this issue Jan 30, 2016 · 8 comments

Comments

@nik-kor
Copy link
Contributor

nik-kor commented Jan 30, 2016

Hi!

I had added the git-hook and it wasn't working. The reason was *.swp file generated by vim.
I was going to create PR but saw the tests and it considered as normal case. But maybe it's a good idea to handle it somehow. E.g. add a list with exceptional extensions or analyse execute permission for the file.

What do you think?

@tarmolov
Copy link
Owner

It should show an error which motivated a developer to fix a file permissions or to remove bad a file.

Didn't it work for you?

@nik-kor
Copy link
Contributor Author

nik-kor commented Jan 31, 2016

Ok. The original problem was with .swp file and what I've got was

console.error('Cannot find git-hooks. Did you install it?');

and it was fixed in 1.0.1 - it's informative now.)

@nik-kor
Copy link
Contributor Author

nik-kor commented Jan 31, 2016

But hey. It's hard to debug hooks with vim anyway.

@tarmolov
Copy link
Owner

Do you have any suggestions?

@nik-kor
Copy link
Contributor Author

nik-kor commented Jan 31, 2016

diff --git a/lib/git-hooks.js b/lib/git-hooks.js
index afd6dc0..2c91347 100644
--- a/lib/git-hooks.js
+++ b/lib/git-hooks.js
@@ -4,6 +4,7 @@ var spawn = require('child_process').spawn;
 var fs = require('fs');
 var fsHelpers = require('./fs-helpers');

+const EXCLUDE_HOOKS_RE = /.swp$/;
 var HOOKS_DIRNAME = 'hooks';
 var HOOKS_OLD_DIRNAME = 'hooks.old';
 var HOOKS_TEMPLATE_FILE_NAME = 'hook-template.js';
@@ -131,7 +132,13 @@ function runHooks(hooks, args, callback) {
         return;
     }

-    var hook = spawnHook(hooks.shift(), args);
+    var hookPath = hooks.shift();
+    if (EXCLUDE_HOOKS_RE.test(hookPath)) {
+        runHooks(hooks, args, callback);
+        return;
+    }
+
+    var hook = spawnHook(hookPath, args);
     hook.on('close', function (code) {
         if (code === 0) {
             runHooks(hooks, args, callback);

@tarmolov
Copy link
Owner

tarmolov commented Feb 1, 2016

It solves the issue only for vim but not for other editors. It seems to solve the issue we need to add some kind of '.githooksignore'.

It'll increase complexity of the module but I'm not sure that this feature are really essential.

@nik-kor
Copy link
Contributor Author

nik-kor commented Feb 1, 2016

Yeah. It sounds more general solution.

пн, 1 Фев 2016, 12:17, Alexander Tarmolov [email protected]:

It solves the issue only for vim but not for other editors. It seems to
solve the issue we need to add some kind of '.githooksignore'.

It'll increase complexity of the module but I'm not sure that this feature
are really essential.


Reply to this email directly or view it on GitHub
#12 (comment)
.

@nik-kor
Copy link
Contributor Author

nik-kor commented Feb 7, 2016

so #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants