rycus86 / githooks

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

Cannot enable/disable shared hook with 'git hooks *able' #65

Closed whisperity closed 4 years ago

whisperity commented 4 years ago

If a shared hook is disabled (by hand at the question), the following pop-up happens next time it would be executed:

* Skipping disabled <user>/.githooks/shared/whisperity_git_hooks/pre-commit/git-clang-format
  Use `git hooks enable pre-commit git-clang-format` to enable it again
  Alternatively, edit or delete the <repo>/.git/.githooks.checksum file to enable it again

Problem is, saying git hooks enable pre-commit git-clang-format will just error with Sorry, cannot find any hooks that would match that, even though git hooks list says:

> pre-commit
  - git-clang-format (pending / new / shared:local)

Editing the "checksum" file works, but it seems the logic to find a hook inside a pulled share is missing.

How I set my working directory up is that I set my own git-hooks repo as a local share and then ran git hooks shared update.

$ cat .githooks/.shared
# Added on <date>
http://github.com/whisperity/git-hooks.git
gabyx commented 4 years ago

This should work, hm... lets see

gabyx commented 4 years ago

Ok, it seems, shared hooks enabling/disabling is not implemented yet. So only local hooks work.

gabyx commented 4 years ago

But saying this, extending to this functionality I am questioning if this manager should stay in "shell". Maybe just rewrite it in GO... :-P. Lots of work, especially the 110 unit tests...

rycus86 commented 4 years ago

Pushed a change that introduces --shared for git hooks enable|disable|accept, see the docs here: https://github.com/rycus86/githooks/blob/master/docs/command-line-tool.md

Let me know how this works out for you!

gabyx commented 4 years ago

What happens if we have 2 shared repos with the same hook name? And we disable them? Thanks for the changes?

rycus86 commented 4 years ago

I think we'll always just find the first one. I believe this is what would happen already if you'd have .githooks/pre-commit/something and .githooks/post-commit/something in the same local repo and do a git hooks disable something

I'm not too worried about this case though, you wouldn't do it in the local repo (or it's at least easy to fix), the problem os if two shared repos give you the same named hook files. Let's worry about this when it's reported as an issue.

whisperity commented 4 years ago

I tried it out, but the code hard-requires the hooks themselves to be in <repo>/.githooks even in the share, whereas the list command finds the hooks even if the script's path is <shared-repo>/pre-commit/git-clang-format.

It is not documented anywhere that shares should also contain scripts in a .githooks directory. I think this either needs to be documented, or the logic expanded to search in the "root directory" of the checked out shares, as using a directory with . in a repository meant to contain just hooks is rather clunky: . inodes are hidden by default...

Doing an cd ~/.githooks/shared/<repo-name>/; ln -s . .githooks does fix the issue, so the overall logic for searching inside the share does work.

rycus86 commented 4 years ago

That's right, I'll have a look at that.

rycus86 commented 4 years ago

OK, added a new test without the .githooks folder in the shared repo, hopefully this should do it.

whisperity commented 4 years ago

Thanks, tried it out in the wild, and seems to work fine. :tada: