observing/pre-commit

Don't work when .git placed in parent directory

Opened this issue ยท 23 comments

Hi! Thanks for amazing solution of hooks implementation for node.js. But could you add support for cases when .git placed in parent directory relative to package.json?

๐Ÿ‘

๐Ÿ‘

@Swaagie Any thoughts on this? I'm neutral about it.

๐Ÿ‘ I have different parts of the project in separate directories within a single repo, this will solve the issue.

I guess we could make this functionality opt-in by specifying the max depth that we can search for a .git folder.

The only complication I can see, if I have multiple projects in a repository in subfolders that use pre-commit.

@tuhoojabotti That's why I'm suggesting opt-in through a field in the package.json

Yeah, I don't see an issue with that, but would it be possible to run the pre-commit hooks of all packages in sub folders? For example if I have a package.json file for both my back-end and front-end I would like to run both pre-commit hooks before allowing commit.

๐Ÿ‘

+1

Happy to give it a shot and create a PR. Could I get a hint please which part of the code to start with?

EDIT: not going to do that, was easier to just change my directory structure ๐Ÿ˜œ

@kosmotaur Probably the installation script of this module: https://github.com/observing/pre-commit/blob/master/install.js#L23-L28 as it checks if the parent folder has .git

Btw, when using git submodules there will be a text file named .git in the same folder that will have a relative path inside to where the submodule real .git folder is.

Maybe this should be checked as well

๐Ÿ‘

Hello, we suffer from the same issue here, and I would like to know if there is some kind of improvement to come (like the opt-in suggested by @3rd-Eden) ?

This would be a great feature, especially for use with mono-repo projects like Lerna. Is there any plans to merge #55, or ways we can pitch in?

+1 Has this been addressed somehow ?

Also, yes, to avoid any cross-OS issues a simple solution I guess would be to put a file calle .git-repo or something at the root where the node_modules folder is which would point to the root of the .git repo and simply fail if not found...

+1!

ai commented

We need this fix in my project with lint-staged.

I think it is very important for big projects with monorepo, when you have client/ and server/ subdirs.

@3rd-Eden how I can help with this issue?

This project sets up hooks which will work when .git is in a parent directory

๐Ÿ‘

I have a .git that's in a parent directory and it seems it's not detected by pre-commit which siletely fails when I installed it.

I tried creating a fake .git/hooks directory in the child directory where I run the npm installation and it works then.

Reading the comments I thought this was fixed?