Sunday, February 12, 2012

Configure Repository In Redmine

As Rubyist, most of us we use Redmine for Project Management and git for source code management. Written using the Ruby on Rails framework, it is cross-platform and cross-database. Redmine is open source and released under the terms of the GNU General Public License v2 (GPL).

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Redmine provides many features out of that is SCM integration (SVN, CVS, Git, Mercurial, Bazaar and Darcs), which I going to explaing you in this blog post.

I am explaning this because, many time we do a code review for team members. Also some time we need to review a perticuler fix done for any bug. At that time it is very difficult to go through a git log.

So it will be great to use to redmine for this, were we can attach a code to feature or bug and even from git log to issue.

Redmine has this great feature,

Now if we have already git server then, then their are two solution available,

  1. Make git server to support http protocol
  2. Replicate git server on Redmine server it self

both above option are very easy but issue in second option. Issue if you have git server which is runnning separately. Which happens in my case.

Our git server is only accessisble via git protocol like

git clone user_name@repository_server:path_to_project.git

Our git server is used by more than 30 developers were more than 13 repositories get accessed. So I don't want to distrub the development process. So I have decided to replicate git server on redmine.

A. Replicate git server to be used by Redmine

  1. Login to your Redmine server from console
  2. Clone the repository with following command
  # change to your respective user 
 $ su - name_of_user   
  # Create a folder to hold your repository
 $ mkdir /any/path/to/create/repo
  # change directory
 $ cd /any/path/to/create/repo
 # Make a bare clone of the repo
 $ git clone --bare ssh://git@reposerver/usr/local/git_root/foo-project.git
  # Switch to repository
 $ cd foo-project.git
  # add orignal repository in newly created repository for fetching changes done in orignal repository 
 $ git remote add origin ssh://git@reposerver/usr/local/git_root/foo-project.git
  # Above command will feches commit from origanl repo
 $ git fetch origin
 $ git reset --soft refs/remotes/origin/master

  #Make sure bypass the password prompt using ssh config for following command to work from crontab.
  # Add the following to your crontab
 */10 * * * * cd /var/local/git_copies/foo-project.git && git fetch origin && git reset --soft refs/remotes/origin/master > /dev/null

Using above command we have setuped a replica of git server on redmine server.

B. Add project repository in Redmine

Go to the redmine, select your project and add repository local path. Goto => setting => repository

C. Fetch commits into redmine

When you first browse the repository, Redmine retrieves the description of all of the existing commits and stores them in the database.
This is done only once per repository but can take a very long time (or even time out) if your repository has hundreds of commits.

To avoid this, you can do it offline.
Run the following rake command on redmine server:

$ ruby script/runner "Repository.fetch_changesets" -e production

All commits will be retrieved in to the Redmine database.

Since Redmdine 0.9.x, you can use following link of your redmine to execute fetch_changesets for a specific project, or all. (=> fetches changesets for all active projects) (=> fetches changesets for project foo only)

Now we have sucessfully configured git reposiroty in Redmine.

Now you can use following link for linking revision and commits to issue and vice-varsa.