-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (26 loc) · 714 Bytes
/
index.js
File metadata and controls
30 lines (26 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use strict";
var fs = require('fs');
var path = require('path');
var template = fs.readFileSync('./hook-template', 'utf-8');
var projectDir = path.resolve(__dirname, '..', '..');
if (process.env.NODE_ENV === 'testing') {
projectDir = path.join(__dirname, 'test');
}
var hookDir = path.resolve(projectDir, '.git/hooks/');
var hooks = [
'pre-commit',
'post-commit',
'post-merge',
'pre-push'
];
hooks.forEach(function(hook) {
installHook(hook);
});
function installHook(hook) {
try {
fs.writeFileSync(path.join(hookDir, hook), template, { mode: '755' });
console.log('installed '+path.join(hookDir, hook));
} catch(error) {
console.error('installing '+hook+' failed: ', error);
}
}