如何让 Redmine 更新其数据库以反映配置的 git 存储库的内容

问题描述

Redmine 3.4.11.stable
Postgresql-9.6
Git-2.24.1

我遇到了一种情况,即在我的一个项目中配置的 git repo 没有被 Redmine 接收到其最近的提交。然而,更新的文件本身可以通过 Redmine 存储库浏览器页面查看。去年秋天和更早的东西都在那里。

我不知道这是怎么发生的,但它已经发生了。如何让 Redmine 重新读取 git 存储库并自行重置?

解决方法

有几种方法可以做到这一点,例如,如果您使用 github repo 之类的方法,那就是在 Redmine 所在的服务器上有一个本地副本,就像一个 cron 作业每 5 分钟更新一次...

所以首先你必须将 repo 克隆到你的 Redmine 用户的 像这样的文件夹,例如:

git clone mygitproject /home/redmine/repos/mygitproject

并且您的 Redmine 用户将拥有如下 cron 条目:

*/5 * * * *  cd /home/redmine/repos/mygitproject && git fetch -q --all -p

然后在 Redmine 中,在您的项目中,设置 -> 存储库 选项卡 会有这样的条目:

/home/redmine/repos/mygitproject

这样你的 Redmine 就会有 5 分钟的延迟。

如果你想实时更改,那么你需要在你的 git 服务器上使用 post-receive hook 来像通过 SSH 登录你的 Redmine 服务器并执行手动 git 更新,以及 wget 脚本来通过 Redmine 存储库更新存储库您可以在 Redmine 的管理设置、存储库选项卡中找到的 web 服务和密钥...

post-receive hook 的整个 shell 代码可能是这样的:

#!/usr/bin/expect -f

spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no redmine@yourserverip
match_max 100000
expect "*?assword:*"
send -- "Password#!\r"
expect "*?elcome*"
send -- "cd redpo\r"
send -- "git pull\r"
expect -re ".*dat"
wget "http://<redmine url>/sys/fetch_changesets?key=<your service key>"

您还可以在此处找到官方指南: https://www.redmine.org/projects/redmine/wiki/HowTo_setup_automatic_refresh_of_repositories_in_Redmine_on_commit

,

我发现解决此问题的唯一方法是删除 Redmine 中的存储库引用,然后将其添加回来。这迫使 Redmine 首先删除然后重建其内部引用。这种方法的缺点是,对问题说明或 wiki 页面中包含的提交的引用会被删除并且不会被重建。