阻止推动者破坏我的中央 Mercurial 存储库

use*_*748 7 mercurial apache-2.2

我正在运行中央 mercurial 存储库,我知道如果远程用户试图将多个“头”强制连接到我的中央存储库,则正常的“推送”命令将停止。目的是远程用户在尝试再次推送之前应该先拉取和合并。

但是,使用hg push --force将覆盖它。我想阻止这种行为。

我目前正在使用hgwebdir.cgi加上一些 apache-auth 的东西来限制用户拉和推的能力。

编辑:一个 pretxnchangegroup 钩子解决了这个问题。钩子工作:

#!/bin/bash
# force-one-head
# add the following to <repository>/.hg/hgrc :
# [hooks]
# pretxnchangegroup.forceonehead = /path/to/force-one-head

if [[ `hg heads -q | wc -l` -gt 1 ]]; then
    echo "There are multiple heads."
    echo "Please 'hg pull' and get your repository up to date first."
    echo "Also, don't 'hg push --force' because that won't work either."
    exit 1
fi
Run Code Online (Sandbox Code Playgroud)

小智 6

这不是 Apache 更改,但您必须在 Mercurial 存储库本身中进行设置。

在接受推送到您的存储库之前,您可以设置运行脚本的挂钩。在由pretxncommitpretxnchangegroup钩子触发的脚本中,您可以检查这些更改是否创建了一个新的头部,如果有则拒绝它们。

有关更多详细信息,请参阅Hg Book 中有关钩子的章节