1

I want to have git repos accessable in redmine. But what about auto update of redmine git repos. I thought redmine will 'read' git repos but it wants to have its own local copy. So then the question of having the latest repo in redmine arises.

I found few solutions using cron but I would prefer to use git hook if possible. Any idea how to make git if there is repository update to also update redmine repository?

redmine wiki provides this solution but I do not understand what it does. Maybe it is what I want? Could somebody explain below code?

echo "Post receive-hook => updating Redmine repository" 
sudo -u my_redmine_user -p secret perl -we '`cd /redmine/repositories/my_repo.git && git fetch && git reset --soft refs/remotes/origin/master`'
Radek
  • 13,813
  • 52
  • 161
  • 255

1 Answers1

4

That looks like it's meant to be placed in the post-receive hook of your central repo. That hook is executed whenever you push into the repo, so it's an ideal place to trigger other operations like this one. (Of course, the post-update hook would also be a reasonable place.)

The hooks are, surprise, in the hooks directory of a bare repo (.git/hooks for a non-bare repo). If you don't already have a post-receive hook, you can just create one: make a file called post-receive in the hooks directory, make it executable, put #!/bin/sh on the first line, then those two lines. If there is already one, just add those two lines to it. Since post-receive is meant mainly for notification-type operations, it's pretty easy for the script to end up being a list of things like this.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • @Jefromi how this script in bare redmine repo A is to be executed if I do push from another repo B to remote github repository C ( A is tracking C but I develop project in B, A and B are on same machine)? – 4pie0 Apr 08 '14 at 19:49
  • @privatedatapublicchannel2 I'm not sure exactly what you're trying to ask. The answer says "[the post-receive] hook is executed whenever you push into the repo" - if that doesn't answer your question, you should probably post a new one, hopefully more clear than your comment. – Cascabel Apr 08 '14 at 20:22
  • @Jefromi I see now, the post-receive has to be put to B repo: to the repo from with I invoke git push, right? then because git push was invoked in this repo B its hook post-receive is run and it cd to my redmine repo A and call git fetch in it – 4pie0 Apr 08 '14 at 20:26
  • @privatedatapublicchannel2 The post-*receive* hook is run in the (presumably remote, bare) repo *receiving* the push. – Cascabel Apr 08 '14 at 20:37
  • Yes, now I see, thank you. I cannot find any hook that is invoked from repository B (executes bash script on B) if I do a push from B. I want to take some action after push - I want to cd to another repo on B and do fetch. I can write a script wrapping git push, cd, git fetch but ideally I would like to execute cd, fetch from hook. – 4pie0 Apr 08 '14 at 20:49
  • @privatedatapublicchannel2 Like I said, if you're really trying to ask something other than "what does post-receive do", post another qusetion (it's probably a dup, but I'm a little busy for searching). – Cascabel Apr 08 '14 at 21:06