gabyx / Githooks

🦎 Githooks: per-repo and shared Git hooks with version control and auto update. [✩Star] if you're using it!
MIT License
102 stars 4 forks source link

`git hooks install` is not installing hooks or is showing failing messages #170

Closed giggio closed 2 months ago

giggio commented 2 months ago

I just ran git hooks install and nothing changed in .git/hooks. I ran it again and files showed up. I'm not sure what happened. Now I ran again and got this:

❯ git hooks install
🦎 Installed '22' Githooks run-wrapper(s) into '/home/user/.dotfiles/.git/hooks'
β›‘  Githooks are configured but Githooks seems not installed in '/home/user/.dotfiles/.git'.
   Neither 'core.hooksPath' set nor run-wrappers installed.
   Hooks might not run!

list is also listing errors. Hooks are installed, see output:

❯ ls -la .git/hooks/
drwxr-xr-x   - user user  2 May 01:24 .
drwxr-xr-x   - user user  2 May 01:24 ..
.rwxr-xr-x 754 user user  2 May 01:24 applypatch-msg
.rwxr-xr-x 754 user user  2 May 01:24 commit-msg
<REMOVED FOR BREVITY>

~/.dotfiles on ξ‚  main πŸ“1⇑1                                                                                                                                                                         at 01:24:46 
❯ git hooks list
β›‘  Githooks are configured but Githooks seems not installed in '/home/user/.dotfiles/.git'.
   Neither 'core.hooksPath' set nor run-wrappers installed.
   Hooks might not run!
🦎 Hook: 'pre-commit' [1]:
    Repository:
     β€’ '01-shellcheck.sh'  :  state: ['active', 'trusted'], type: 'repo', ns-path: 'ns:gh-self/pre-commit/01-shellcheck.sh'
🦎 Total listed hooks: '1'.

I'm running git hooks from main, using nix.

gabyx commented 2 months ago

Seems weird and like a small bug I supposedly fixed? After installing git hook install can you post the full ls -al $(git rev-parse --git-common-dir)/hooks. It should contain a githooks-contains-run-wrappers file. If not that is kind of weird. Are you sure that git hooks is using the build executable from Nix and not the ~/.githooks/bin thing still installed?

The relevant code which triggers this is :

if hasHooksConfigured &&
            !localCoreHooksPathSet && !globalCoreHooksPathSet &&
            !hasRunWrappers {

!hasRunWrappers is the not existence of githooks-contains-run-wrappers file inside the hook directory. Are you using workspaces?

BR

gabyx commented 2 months ago

I reproduced the bug, thanks for the report. Its just awrong warning. Trying to fix it.

gabyx commented 2 months ago

Found the typo in the warning logic: Fixing it in 30min, than it works hopefully.

gabyx commented 2 months ago

@giggio: You should probably prefer to install only a link (core.hooksPath) with git hooks install. You can do this by git hooks uninstall and cleaning git config githooks.maintainedHooks (this settings will force run-wrappers into the current repo). You can set this to a meaningful value globally when git hooks installer runs, to just maintain a set of meaningful hooks in the Githooks hooksDir (=<install-prefix>/templates/hooks)

giggio commented 2 months ago

I am no longer seeing failing messages, but I still see the bug of not installing: image

But something ran, I see githooks.registered is now set to true.

gabyx commented 2 months ago

it installed, it set the core.hooksPath.

giggio commented 2 months ago

Oh, yes, it did. So now we don't need the run wrappers on the local directory anymore? Ok, cool!

gabyx commented 2 months ago

@giggio: Correct, it will only use run-wrappers on the local directory when you use --maintained-hooks on git hooks install

gabyx commented 2 months ago

You can also use that on githooks-installer