bahmutov / pre-git

Automatically install pre-commit / pre-push hooks in your git repo
168 stars 22 forks source link

Cannot use pre-git when node_modules is not in the same folder as .git folder #101

Open pascalvaccaro opened 7 years ago

pascalvaccaro commented 7 years ago

This is quite annoying: I have a project where the repo contains java back-end sources and the front-end sources in a separate folder, like so:

. |.git |project-backend |project-scripts |project-ui | |__node_modules | |__package.json |____project-webapp

Is there any way to tell pre-git to look for package.json in a specific folder? If not can we add this feature? I'm up for it :-)

bahmutov commented 7 years ago

Hmm, how would the fit hook script find the package json file?

Sent from my iPhone

On Dec 7, 2016, at 12:31, Ripley511 notifications@github.com wrote:

This is quite annoying: I have a project where the repo contains java back-end sources and the front-end sources in a separate folder, like so:

. |.git |project-backend |project-scripts |project-ui | |__node_modules | |__package.json |____project-webapp

Is there any way to tell pre-git to look for package.json in a specific folder? If not can we add this feature? I'm up for it :-)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

pascalvaccaro commented 7 years ago

We have to assume the user pwd can be anywhere from the deepest to the root folder of his git repository. Once we find the root (cd.. until pwdis equal to GIT_ROOT), we scan every sub-folder in the root folder for a file named 'package.json', cd to that folder and run the hook commands. Does this solution make sense?

You may even find situations where several sub-folders contain a package.json, each with different commands associated to their git-hooks. It might be complicated though not impossible, in my opinion, to run individual scripts for each of them (but this is another subject).

bahmutov commented 7 years ago

sure, so breadth first search for package.json with pre-git configured. Works for me if you want to implement and send a merge request

elawad commented 7 years ago

Here's an idea used by another git-hook package. https://github.com/okonet/lint-staged#working-from-a-subdirectory