HowTo Easily integrate a (SSH secured) GIT repository into redmine » History » Version 7
Sergey Spivak, 2020-02-12 09:01
--prune key should be used to delete old branches from redmine-side repo copy
1 | 1 | Matthias B. | h1. HowTo: Easily integrate a (SSH secured) GIT repository into redmine |
---|---|---|---|
2 | |||
3 | {{>TOC}} |
||
4 | |||
5 | h2. Scope |
||
6 | |||
7 | This HowTo will show how to integrate a GIT repository to your redmine project and how to keep the repository up to date. |
||
8 | |||
9 | |||
10 | h2. Prerequisites |
||
11 | |||
12 | * The owner of your redmine-directory needs an SSH-Key and (reading) access to the repository you want to integrate in redmine. |
||
13 | * A directory to clone the GIT-repository is needed. |
||
14 | * Redmine must find the GIT-binaries, that means GIT must be installed. You can check this in redmine in the "administration > repositories" settings. If there is green checkmark everything is fine. If not you have to install GIT first, e.g. via "apt-get install" |
||
15 | |||
16 | h3. Example configuration |
||
17 | |||
18 | To better understand this HowTo I will use the following configuration |
||
19 | |||
20 | * My owner of redmine is called "redmine" |
||
21 | * My redmine main directory is "/var/lib/redmine" and I will create a subdirectory "repos" there, where I clone the repositories. So the full path of this directory is "/var/lib/redmine/repos/" |
||
22 | * The URL of my repo is "git.my-url.com", the name "my_repo", so full URL is "git@git.my-url.com:my_repo" |
||
23 | |||
24 | |||
25 | h2. Step 1: Clone the repositories |
||
26 | |||
27 | First we need to clone the repository as a *MIRROR* (not BARE!) repository. A mirror repository has no workfiles but only the commit information what is all we need for redmine. |
||
28 | |||
29 | We switch to redmine-user and clone the repository into the choosen directory. |
||
30 | <pre> |
||
31 | sudo -su redmine |
||
32 | cd /var/lib/redmine/repos/ |
||
33 | git clone --mirror git@git.my-url.com:my_repo my_repo |
||
34 | </pre> |
||
35 | |||
36 | Now all repository information are on disk, but redmine don't knows anything about that. So in the next step we will change this. |
||
37 | |||
38 | 5 | Toshi MARUYAMA | |
39 | 1 | Matthias B. | h2. Step 2: Introduce the repository to redmine |
40 | |||
41 | 5 | Toshi MARUYAMA | Inside redmine we open the "administration > project -> repositories" dialog. You can access this dialog also via "project -> settings -> repositories". There we add a new repository |
42 | 4 | Marcus Mueller | |
43 | 1 | Matthias B. | <pre> |
44 | Type: GIT |
||
45 | Main-repository: check this if the cloned repository is you main repository, if not leave it unchecked. |
||
46 | Name (redmine intern): I suggest to choose the same name as the repository, e.g. "my_repo" |
||
47 | 5 | Toshi MARUYAMA | Path: Absolute path of the repository, e.g. "/var/lib/redmine/repos/my_repo" |
48 | 1 | Matthias B. | </pre> |
49 | |||
50 | Now redmine knows the repository. If you open the "repository"-tab inside your project you will see the repository tree, last commits and so on. |
||
51 | |||
52 | *Note*: When you open the dialog redmine fetchs all changeset *the local repository and the redmine database* since the last time anyone opend this dialog. Especially opening the dialog for the first time of a large repository may take very long. Don't cancel the progress, just let redmine work until it has finished. *Possible Fallacy*: When opening the dialog redmine *DOESN'T* fetch new commits out of GIT! This means that you will never see new commits inside redmine if you don't update the local GIT repository. For that we will write a cronjob in step 3. |
||
53 | 5 | Toshi MARUYAMA | |
54 | 1 | Matthias B. | h2. Step 3: Adding a cronjob to fetch the GIT-repository |
55 | |||
56 | 6 | @ go2null | To keep the GIT repository automatically up to date we will add a cronjob. |
57 | 1 | Matthias B. | |
58 | We open the user specified crontab for the user "redmine" and add a cronjob to fetch all branches every five minutes. |
||
59 | <pre> |
||
60 | sudo crontab -e -u redmine |
||
61 | |||
62 | 7 | Sergey Spivak | */5 * * * * cd /var/lib/redmine/repos/my_repo && git remote update --prune |
63 | 1 | Matthias B. | </pre> |
64 | |||
65 | |||
66 | Alternatively we can directly edit the "/etc/crontab"-file. If we do this we have to add the username of the repository-owner who should execute the commands. |
||
67 | <pre> |
||
68 | nano /etc/crontab |
||
69 | 7 | Sergey Spivak | */5 * * * * redmine cd /var/lib/redmine/repos/my_repo && git fetch --all --prune |
70 | 1 | Matthias B. | </pre> |
71 | |||
72 | *NOTE* If you clone multiple repositories you have to add a crontab-line for every repository. |