rycus86 / githooks

Githooks: per-repo and global Git hooks with version control
MIT License
380 stars 19 forks source link

Why does this test pass in core-hooks-path mode? #163

Open gabyx opened 1 year ago

gabyx commented 1 year ago

Hi Rycus,

Just curious: Trying to understand why this test passes when using core.hooksPath. It seems that it sets init.templateDir as well? Isnt this strange, do you still know the background of this?

https://github.com/rycus86/githooks/blob/a988d08cd1a61581af844f57c2a3b47ef8f8a785/tests/step-001.sh#L12

rycus86 commented 1 year ago

Hey Gabriel 👋

That looks like it does a simple (unopinionated) install, so it doesn't matter if core.hooksPath is set or not, and then tests that our hooks are installed in the current repo's .git folder. Does that help?

gabyx commented 1 year ago

Ah, jeah it installs the templates into /usr/share/git-core/templates/hooks which is used by default by Git as template dir.

My test 001 is failing now because I set core.hooksPath=~/.githooks/templates

In some latest PR on my repo I tried to simplify the install behaviors because I found it a bit confusing. When use-core-hookspath is used it does the same search mechanism (determining the template directory by looking at GIT_TEMPLATE_DIR etc etc etc) as in normal mode. This is kind of strange I find. Do you still know the decision why that was done? I think its strange because, when you use core.hooksPath and at the same time install it probably into some used template dir by Git (GIT_TEMPLATE_DIR or even the default location), you basically have both things, the hooks installed into each and every repository and at the same time using core.hooksPath=/usr/share/git-core/templates/hooks (test-001) not using the .git/hooks/... . This puzzels me. Ok it does not hurt, but this logic bit me now when I implemented a manual install which does not set init.templateDir nor core.hooksPath. Probably need to adjust the tests here and there.

I changed the install behavior such that it only does that search template dir stuff in "normal" install mode. In core.hooksPath install mode it really does not look at any template dir and just looks at core.hooksPath , so if its not set it defaults to ~/.githooks/templates. Still not quite sure if I miss something.

https://github.com/gabyx/Githooks/pull/124/files#diff-993e24ee57b2d727e498129fd5d3b67486518e99aa54a6ac18da83ba7728fe49R50-R51

rycus86 commented 1 year ago

Hm, yeah I can't remember implementation details now. I probably wanted templates to always exist, but when core.hooksPath is used that perhaps doesn't matter as much I guess.

gabyx commented 1 year ago

Ok, jeah no worries. Thanks for the explanations. I think it makes sense to have hook run-wrappers always available. I try :crossed_fingers: to just not put them into a "template" area which Githooks uses in this PR. It makes things a little less complex, and more predictable.