githooks icon indicating copy to clipboard operation
githooks copied to clipboard

Using core.hooksPath: also execute in `repo/hooks` folder?

Open gabyx opened this issue 5 years ago • 2 comments

I have the following szenario I was thinking about.

When using Gitea, it will create repos for you somewhere on the server. Assume there is githooks installed. Because Gitea is not aware of githooks, it just forcefully overwrites into the bare repo.git/hooks directory some hooks it need to run. Thats kind of bad if githooks init.templateDir is in place...

I actually want for all repos on the server to be using githooks. Thats why I installed githooks with core.hooksPath

  • I copied the relvant Gitea hooks (which get installed whenever a new repo is created) to the core.hooksPath folder first,
  • then installed githooks over it (which will replace them)
  • core.hooksPath is now running for every repo, and also executing the "execute_old_hook_if_available" from Gitea

Gitea can now create new repos and every thing is fine since the local repo.git/hooks gets ignored anyway and these hooks are now executed since I copied them in the first place.

I was wondering: Could we make the base-template such that when githooks.useCoreHooksPath is true we can additionally (maybe as a opt-in) also execute the hooks in GIT_DIR/hooks. In that way I dont need to clumsily copy the Gitea hooks to the core.hooksPath ( I even dont know if there are not somewhen more hooks or different ones and so forth...).

So the procedure whould be:


   if are_githooks_disabled; then
        execute_lfs_hook_if_appropriate "$@" || return 1
        execute_old_hook_if_available "$@" || return 1
        return
    fi

    execute_lfs_hook_if_appropriate "$@" || return 1

   # NEW -------------
   if githooks.useCoreHooksPath is true and option-setting is enabled;  then
        execute_all_hooks_in "$GIT_DIR/hooks"
   fi
   # NEW -------------

    # Execute old replaced hooks next to where the base-template-wrapper.sh
    execute_old_hook_if_available "$@" || return 1

    # Global setup
    execute_global_shared_hooks "$@" || return 1

    # Repository local setups
    execute_local_shared_hooks "$@" || return 1
    execute_all_hooks_in "$(pwd)/.githooks" "$@" || return 1

What do you think? I am really not sure if this is really good to support... hm... It just solves my problem but its another setup which makes things to understand a bit harder...

gabyx avatar Sep 04 '20 20:09 gabyx

I'm OK with this change if it's behind an opt-in flag you manually have to enable on your installation.

rycus86 avatar Sep 05 '20 00:09 rycus86

i think we need to make sure that we dont accidentally execute githooks wrapper scripts again ;) if they are still in place accidentally, hmm but thats cumbersome to detect :)

Von meinem iPhone gesendet

Am 05.09.2020 um 02:04 schrieb Viktor Adam [email protected]:

I'm OK with this change if it's behind an opt-in flag you manually have to enable on your installation.

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

gabyx avatar Sep 05 '20 10:09 gabyx