observing / pre-commit

Automatically installs a git pre-commit script in your git repository which runs your `npm test` on pre-commit
MIT License
1.88k stars 152 forks source link

Configurable git root #78

Open alex-pex opened 8 years ago

alex-pex commented 8 years ago

Hello,

I have a multi-technology / single-repository project, something like that :

The problem is : the install.js doesn't find the .git directory, because it isn't in frontend directory but 1 level up. I don't know how to detect accuratly the git root, but maybe we can specify it manually in package.json, along side pre-commit scripts ?

yairEO commented 7 years ago

it's ridicules this code doesn't check upper directories if .git folder isn't found where the package.json is. it's very very common not to have .git in the same level as the package.json file. :/

uninstalling after finding this out.

tpizza commented 7 years ago

I ran into this exact same problem today!

+1

Adding something like a "pre-commit-root" key to package.json should be more than adequate for an override.

EliasJorgensen commented 7 years ago

This would be incredibly useful! Someone please implement this!

macrozone commented 7 years ago

run into the same issue, uninstall

jmenglis commented 7 years ago

Same issue here. Unfortunately.

macrozone commented 7 years ago

Switched to https://github.com/typicode/husky

jukben commented 7 years ago

@macrozone Thanks for the tip, I just tried to involve Husky into our codebase together with https://github.com/okonet/lint-staged and it works like a charm!

jmenglis commented 7 years ago

@macrozone Appreciate it. Up and working now with husky.

micky2be commented 7 years ago

Need this

catdna commented 7 years ago

Also doesn't work where cloned submodules have a '.git' file which points to the real git folder, eg:

my-project/linked-submodule/.git

the contents are :

gitdir: ../.git/modules/linked-submodule

the install.js file bails because of the code:

var git = path.resolve(root, '.git')
  , 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.
//
if (!exists(git) || !fs.lstatSync(git).isDirectory()) return;

so 'git' is most definitely not a folder (just contains the 'real' location of the .git folder)

IAMtheIAM commented 7 years ago

People do need this. We should just be able to configure the root as suggestions using a key in package.json as suggested. Or, it should auto detect.

Update: I also switched to https://github.com/typicode/husky - it works exactly like it should out of the box, even with the .git folder at level up from the project files. Pre-commit could take some hints from Husky's code, to get this similar smoothness of workflow.