rycus86 / githooks

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

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

Open gabyx opened 4 years ago

gabyx commented 4 years ago

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

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...

rycus86 commented 4 years ago

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

gabyx commented 4 years ago

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 notifications@github.com:

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.