2
votes

There are many similar topics (many of them very old) but I am still lost. I have two servers, one has gitolite setup, and another has redmine setup. User is pushing changes to the repository created on gitolite server. Redmine is a user on this gitolite server and is pulling changes from it and showing them in browser.

More precisely, I have used the following line on redmine server:

git clone --mirror ssh://gitolite3@gitoliteserver/testing

Then, I configured this repository (testing.git) as a known repository to redmine - redmine can use bare and local repositories, only.

When user push changes to gitolite server, redmine does not automatically show them. I have to do the following on redmine server:

cd testing.git
git remote update

I could use cron on redmine server for regular updating repository testing.git. But many says this is inefficient and propose hooks. However, information are very confusing. Can you help me by answering if cron is a viable solution and if "git remote update" is a correct command for this cron? Or give me a clean example how to use hooks for my problem.

Not directly connected to the question, but I have to say. For me, non-native english, words as miror, mirrored, mirroring, etc. are hard to follow, please use alice and bob and such more easy terms. Even the word remote is confusing, if I am on A then B is remote for me, but if I am on B then A is remote for me. Thus, it is hard to read about git on the net, and the things are further complicated by the facts, that some solutions are github or bitbucket only variants.

2

2 Answers

2
votes

The first way that I would choose is to use Redmine + Gitolite integration via dedicated plugin, as explained here:

http://redmine-git-hosting.io/

Second way, is what you have attempted, so:

Pulling the changes via cron job or some other kind of scheduled task is legit thing to do, however then some delay exists between commit and a cron job, and also unnecessary utilization of resources like networking and cpu for testing repository even if there is no change...

In order to properly utilize given resources, a recommended way are hooks, in both Redmine and git server.

So on your gitolite, you need to have post-receive hook, which would perform:

  1. update of your repo tracked by Redmine (you can do that in multiple ways, one of ways is to use sshpass or to use expect to login into Redmine server and perform git pull of changes)
  2. trigger the Redmine's repository update hook, which is described here: https://www.redmine.org/projects/redmine/wiki/HowTo_setup_automatic_refresh_of_repositories_in_Redmine_on_commit

So for example, a git's post-receive hook would look like:

#!/bin/bash
/usr/bin/sshpass -pPassword ssh -o StrictHostKeyChecking=no user@server 'cd /home/user/repo/ && git pull origin master'
curl "http://<redmine url>/sys/fetch_changesets?key=<your service key>" 

Redmine webservice key for updating repositories can be found in Administration | Settings | Repository tab

2
votes

Here are details how I applied the accepted answer (solution with hooks). Any comment is welcome.

I have two computers and I will refer to them as gitolite3 and redmine, respectively.

  1. On computer gitolite3, I have edited .gitolite.rc and uncommented the following line:

    # allow repo-specific hooks to be added
    'repo-specific-hooks',
    
  2. On computer gitolite3, I have created file local/hooks/repo-specific/deploy-redmine-testing.sh

    #!/bin/bash
    ssh -p 22 redmine@redmine '/home/redmine/gitrepo-update.sh'
    
  3. On computer gitolite3, I have edited .gitolite/conf/gitolite.conf

    repo testing
        RW+     =   @all
        option hook.post-receive  =  deploy-redmine-testing.sh
    
  4. On computer redmine, I created /home/redmine/gitrepo-update.sh

    #!/bin/bash
    if [ -d /home/redmine/gitrepo/testing.git ]; then
      cd /home/redmine/gitrepo/testing.git
      git remote update
    fi
    
  5. On computer gitolite3, if repository testing does not exist then after commit and push it will be automaticaly created

  6. On computer redmine, I have created bare mirror of the repository testing@gitolite3

    git clone --mirror ssh://gitolite3@gitolite3:22/testing
    
  7. Any further commit into repository testing at gitolite3 will be replicated to repository at redmine

  8. If GUI on redmine is not showing all the content (e.g. it shows only the last revision) then you should delete the entry in GUI and recreate it.