@@ -16,9 +16,31 @@ var fs = require('fs')
1616// `pre-commit` file. The path needs to be absolute in order for the symlinking
1717// to work correctly.
1818//
19- var git = path . resolve ( root , '.git' )
20- , hooks = path . resolve ( git , 'hooks' )
21- , precommit = path . resolve ( hooks , 'pre-commit' ) ;
19+
20+ var git = getGitFolderPath ( root ) ;
21+
22+ // Function to recursively finding .git folder
23+ function getGitFolderPath ( currentPath ) {
24+ var git = path . resolve ( currentPath , '.git' )
25+
26+ if ( ! exists ( git ) || ! fs . lstatSync ( git ) . isDirectory ( ) ) {
27+ console . log ( 'pre-commit:' ) ;
28+ console . log ( 'pre-commit: Not found .git folder in' , git ) ;
29+
30+ var newPath = path . resolve ( currentPath , '..' ) ;
31+
32+ // Stop if we on top folder
33+ if ( currentPath === newPath ) {
34+ return null ;
35+ }
36+
37+ return getGitFolderPath ( newPath ) ;
38+ }
39+
40+ console . log ( 'pre-commit:' ) ;
41+ console . log ( 'pre-commit: Found .git folder in' , git ) ;
42+ return git ;
43+ }
2244
2345//
2446// Resolve git directory for submodules
@@ -39,7 +61,15 @@ if (exists(git) && fs.lstatSync(git).isFile()) {
3961// Bail out if we don't have an `.git` directory as the hooks will not get
4062// triggered. If we do have directory create a hooks folder if it doesn't exist.
4163//
42- if ( ! exists ( git ) || ! fs . lstatSync ( git ) . isDirectory ( ) ) return ;
64+ if ( ! git ) {
65+ console . log ( 'pre-commit:' ) ;
66+ console . log ( 'pre-commit: Not found any .git folder for installing pre-commit hook' ) ;
67+ return ;
68+ }
69+
70+ var hooks = path . resolve ( git , 'hooks' )
71+ , precommit = path . resolve ( hooks , 'pre-commit' ) ;
72+
4373if ( ! exists ( hooks ) ) fs . mkdirSync ( hooks ) ;
4474
4575//
0 commit comments