如何配置Mercurial服務器以限制提交到已命名分支關閉後的提交?我只希望存儲庫管理員能夠重新打開分支。阻止添加到已關閉分支的提交推送
https://www.mercurial-scm.org/wiki/PruningDeadBranches表示可以通過在變更集的額外字段中「close = 1」來標識關閉的變更集。目前還不清楚如何使用Mercurial API來讀取變更集的額外字段。
如何配置Mercurial服務器以限制提交到已命名分支關閉後的提交?我只希望存儲庫管理員能夠重新打開分支。阻止添加到已關閉分支的提交推送
https://www.mercurial-scm.org/wiki/PruningDeadBranches表示可以通過在變更集的額外字段中「close = 1」來標識關閉的變更集。目前還不清楚如何使用Mercurial API來讀取變更集的額外字段。
有一個ACL擴展與Mercurial一起發佈。 您應該能夠通過拒絕提交給除管理員之外的每一個來指定凍結分支。我不確定名稱分支機構是否可以利用此設施。
配置ACL:
[acl.deny.branches]
frozen-branch = *
[acl.allow.branches]
branch_name = admin
服務器不能限制提交,但它可以拒絕接受違反約束的推動。這裏是你可以把一臺服務器上,以拒絕有對於關閉分支任何變更任何推動鉤:
#!/bin/sh
for thenode in $(hg log -r $HG_NODE:tip --template '{node}\n') ; do
if hg branches --closed | grep -q "^$(hg id --branch -r $thenode).*\(closed\)" ; then
echo Commits to closed branches are not allowed -- bad changeset $thenode
exit 1
fi
done
你會安裝鉤子是這樣的:
[hooks]
prechangegroup = /path/to/that.sh
幾乎可以肯定一種使用帶引用的API的in-python鉤子來實現它的方法,但shell鉤子也能很好地工作。
儘管我不能低估這個答案,但應該指出,這不起作用,因爲$ HG_NODE不適用於prechangegroup。不幸的是,修復pretxnchangegroup的掛鉤也不起作用,因爲然後對分支是否關閉進行更改不再起作用,因爲pretxnchangegroup試圖添加更改集,因此分支已重新打開。我寧願編寫一個shell鉤子,但仍然想知道如何爲了這裏討論的特定目的做到這一點。 – 2015-08-14 13:01:47
我得到了這份工作。您可以使用pretxnchangegroup鉤子並使用與上面列出的腳本類似的腳本來檢查$ HG_NODE中的每個節點:提示其父項之一在其額外字段中是否有「close = 1」。您可以使用hg log -r $ parentNode --template'{extras}'| grep -q「close = 1」來執行後面的檢查。 – 2015-08-14 15:05:23
這是一個進程內鉤子,它應該拒絕關閉分支上的其他變更集。
from mercurial import context, ui
def run(ui, repo, node, **kwargs):
ctx = repo[node]
for rev in xrange(ctx.rev(), len(repo)):
ctx = context.changectx(repo, rev)
parent1 = ctx.parents()[0]
if parent1 != None and parent1.extra().get('close'):
ui.warn("Commit to closed branch is forbidden!\n")
return True
return False
鉤可在pretxncommit模式(在本地檢查提交事務)或pretxnchangegroup模式下運行(選中時的變更從外部回購添加的)用下面的hgrc條目:
[hooks]
pretxncommit.forbid_commit_closed_branch = python:/path/to/forbid_commit_closed_branch.py:run
pretxnchangegroup.forbid_commit_closed_branch = python:/path/to/forbid_commit_closed_branch.py:run
不知道是否這個鉤子將在2.2之前的Mercurial版本中工作。
該死!阻止意外犯下封閉分支的人應該更容易。 – Rory 2011-05-11 23:53:03
大家一直在說「提交」,但你的意思是「推」。你永遠不會阻止一個堅定的提交者,你只是拒絕他們的推動。 – 2012-09-18 13:36:18