Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion install.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ var git = path.resolve(root, '.git')
, hooks = path.resolve(git, 'hooks')
, precommit = path.resolve(hooks, 'pre-commit');

// If the .git is a file it is probably a submodule
if (fs.lstatSync(git).isFile()) {
// the .git file should contain "gitdir: ../.git/modules/path" if we use submodules
var fileContents = fs.readFileSync(git, 'utf8');
if (fileContents.match(/^gitdir:/)) {
git = path.resolve(root, fileContents.replace(/gitdir: /, '').replace(/^\s+|\s+$/g, ''));
hooks = path.resolve(git, 'hooks');
precommit = path.resolve(hooks, 'pre-commit');
}
}

//
// Bail out if we don't have an `.git` directory as the hooks will not get
// triggered. If we do have directory create a hooks folder if it doesn't exist.
Expand Down Expand Up @@ -51,7 +62,6 @@ catch (e) {}
// as stashing - unstashing the unstaged changes)
// TODO: we could keep launching the old pre-commit scripts
var hookRelativeUnixPath = hook.replace(root, '.');

if(os.platform() === 'win32') {
hookRelativeUnixPath = hookRelativeUnixPath.replace(/[\\\/]+/g, '/');
}
Expand Down
16 changes: 15 additions & 1 deletion uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
var fs = require('fs')
, path = require('path')
, exists = fs.existsSync || path.existsSync
, precommit = path.resolve(__dirname, '../..', '.git', 'hooks', 'pre-commit');
, root = path.resolve(__dirname, '..', '..')
, git = path.resolve(root, '.git')
, hooks = path.resolve(git, 'hooks')
, precommit = path.resolve(hooks, 'pre-commit');

// If the .git is a file it is probably a submodule
if (fs.lstatSync(git).isFile()) {
// the .git file should contain "gitdir: ../.git/modules/path" if we use submodules
var fileContents = fs.readFileSync(git, 'utf8');
if (fileContents.match(/^gitdir:/)) {
git = path.resolve(root, fileContents.replace(/gitdir: /, '').replace(/^\s+|\s+$/g, ''));
hooks = path.resolve(git, 'hooks');
precommit = path.resolve(hooks, 'pre-commit');
}
}

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