|
5 | 5 | //
|
6 | 6 | var fs = require('fs')
|
7 | 7 | , path = require('path')
|
8 |
| - , spawn = require('cross-spawn') |
| 8 | + , os = require('os') |
9 | 9 | , hook = path.join(__dirname, 'hook')
|
10 | 10 | , root = path.resolve(__dirname, '..', '..')
|
11 | 11 | , exists = fs.existsSync || path.existsSync;
|
@@ -47,15 +47,28 @@ if (exists(precommit) && !fs.lstatSync(precommit).isSymbolicLink()) {
|
47 | 47 | try { fs.unlinkSync(precommit); }
|
48 | 48 | catch (e) {}
|
49 | 49 |
|
| 50 | +// Create generic precommit hook that launches this modules hook (as well |
| 51 | +// as stashing - unstashing the unstaged changes) |
| 52 | +// TODO: we could keep launching the old pre-commit scripts |
| 53 | +var hookRelativeUnixPath = hook.replace(root, '.'); |
| 54 | +if(os.platform() === 'win32') { |
| 55 | + hookRelativeUnixPath = hookRelativeUnixPath.replace(/[\\\/]+/g, '/'); |
| 56 | +} |
| 57 | +var precommitContent = '#!/bin/bash' + os.EOL |
| 58 | + + hookRelativeUnixPath + os.EOL |
| 59 | + + 'RESULT=$?' + os.EOL |
| 60 | + + '[ $RESULT -ne 0 ] && exit 1' + os.EOL |
| 61 | + + 'exit 0' + os.EOL; |
| 62 | + |
50 | 63 | //
|
51 | 64 | // It could be that we do not have rights to this folder which could cause the
|
52 | 65 | // installation of this module to completely fail. We should just output the
|
53 | 66 | // error instead destroying the whole npm install process.
|
54 | 67 | //
|
55 |
| -try { fs.symlinkSync(path.relative(hooks, hook), precommit, 'file'); } |
| 68 | +try { fs.writeFileSync(precommit, precommitContent); } |
56 | 69 | catch (e) {
|
57 | 70 | console.error('pre-commit:');
|
58 |
| - console.error('pre-commit: Failed to symlink the hook file in your .git/hooks folder because:'); |
| 71 | + console.error('pre-commit: Failed to create the hook file in your .git/hooks folder because:'); |
59 | 72 | console.error('pre-commit: '+ e.message);
|
60 | 73 | console.error('pre-commit: The hook was not installed.');
|
61 | 74 | console.error('pre-commit:');
|
|
0 commit comments