gitolite hook for specific repository

前端 未结 2 550
轻奢々
轻奢々 2021-02-02 18:16

I don\'t understand how do I create a post-receive hook for a specific repository in gitolite (non-root install)

My bare repository contains a website t

2条回答
  •  渐次进展
    2021-02-02 18:39

    This is a fairly common need for someone using gitolite, and appears to be a little difficult to tie up loose ends when being not a very advanced user (at leas it was for me).

    Following stackoverflow's and gitolite's links back and forth can be a little confusing. These are my conclusions and the path I followed to be able to achieve this.

    As @VonC mentioned creating repository specific hooks is already possible since version 3.5.3.1 (github link)

    Update/Upgrade Gitolite

    The first thing you should do is update your gitolite repo. So ssh into your server that is hosting gitolite and move to the location where gitolite is installed (usually /home/git/gitolite) as the git user (usually git)

    Example:

    $ ssh myusername@devserver.com
    $ sudo su - git
    $ pwd
    /home/git
    $ cd gitolite
    

    Then we have to upgrade gitolite. To do so, first we need to update the gitolite repository

    $ git pull
    

    Then we have to repeat the install command (make sure you use the same arguments as before)

    $ ./install
    

    And finally run the setup again.

    $ gitolite setup
    

    If that doesn't work, you probably haven't set up gitolite executable in your PATH, so you could do something like this:

    $ src/gitolite setup

    Gitolite Settings (The "RC" file)

    This was one of the parts that confused me the most, but it ended up it was pretty straight forward.

    The famous "rc" file is located at git's home directory /home/git/.gitolite.rc. There make sure you have a variable called LOCAL_CODE, you should see something like this on that file, if not, add it.

    LOCAL_CODE => "$ENV{HOME}/.gitolite/local"
    

    And in the "commands an feature to enable" section you should make sure that repo-specific-hooks is available, if not, add it.

    ENABLE => [
    
        # COMMANDS
    
            # These are the commands enabled by default
            'help',
            'desc',
            'info',
            ...,
            ...,
            ...,
            'repo-specific-hooks'
            ...,
            ...,
            ...
    ]
    

    Here is the link to the documentation

    Writing Repository Specific Hooks

    Finally, in your local gitolite-admin repository create the following directories hooks/repo-specific under the directory you just set in the LOCAL_CODE variable, for example:

    gitolite_admin/local/hooks/repo-specific
    

    After that you can actually add your hooks scripts to that location and manage them through the gitolite conf file as stated in the documentation. Make sure the scripts are executable.

    repo foo
    RW+                       =   @all
    option hook.post-receive  =   deploy
    

    Again, I hope this helps some of you guys.

    Cheers!

提交回复
热议问题