Skip to content

Commit 5eb7b9b

Browse files
faazshift3rd-Eden
authored andcommitted
Support for git repos as submodules (#96)
1 parent 66b95fd commit 5eb7b9b

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

install.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ var git = path.resolve(root, '.git')
2020
, hooks = path.resolve(git, 'hooks')
2121
, precommit = path.resolve(hooks, 'pre-commit');
2222

23+
//
24+
// Resolve git directory for submodules
25+
//
26+
if (exists(git) && fs.lstatSync(git).isFile()) {
27+
var gitinfo = fs.readFileSync(git).toString()
28+
, gitdirmatch = /gitdir: (.+)/.exec(gitinfo)
29+
, gitdir = gitdirmatch.length == 2 ? gitdirmatch[1] : null;
30+
31+
if (gitdir !== null) {
32+
git = path.resolve(root, gitdir);
33+
hooks = path.resolve(git, 'hooks');
34+
precommit = path.resolve(hooks, 'pre-commit');
35+
}
36+
}
37+
2338
//
2439
// Bail out if we don't have an `.git` directory as the hooks will not get
2540
// triggered. If we do have directory create a hooks folder if it doesn't exist.

uninstall.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@
33
var fs = require('fs')
44
, path = require('path')
55
, exists = fs.existsSync || path.existsSync
6-
, precommit = path.resolve(__dirname, '../..', '.git', 'hooks', 'pre-commit');
6+
, root = path.resolve(__dirname, '..', '..')
7+
, git = path.resolve(root, '.git');
8+
9+
//
10+
// Resolve git directory for submodules
11+
//
12+
if (exists(git) && fs.lstatSync(git).isFile()) {
13+
var gitinfo = fs.readFileSync(git).toString()
14+
, gitdirmatch = /gitdir: (.+)/.exec(gitinfo)
15+
, gitdir = gitdirmatch.length == 2 ? gitdirmatch[1] : null;
16+
17+
if (gitdir !== null) {
18+
git = path.resolve(root, gitdir);
19+
}
20+
}
21+
22+
//
23+
// Location of pre-commit hook, if it exists
24+
//
25+
var precommit = path.resolve(git, 'hooks', 'pre-commit');
726

827
//
928
// Bail out if we don't have pre-commit file, it might be removed manually.

0 commit comments

Comments
 (0)