我希望有一个Mercurial钩子,它将在提交事务之前运行,如果提交的二进制文件大于1兆字节,该事务将中止事务.我找到了以下代码,除了一个问题,它工作正常.如果我的更改集涉及删除文件,则此挂钩将引发异常.
钩子(我正在使用pretxncommit = python:checksize.newbinsize):
from mercurial import context, util
from mercurial.i18n import _
import mercurial.node as dpynode
'''hooks to forbid adding binary file over a given size
Ensure the PYTHONPATH is pointing where hg_checksize.py is and setup your
repo .hg/hgrc like this:
[hooks]
pretxncommit = python:checksize.newbinsize
pretxnchangegroup = python:checksize.newbinsize
preoutgoing = python:checksize.nopull
[limits]
maxnewbinsize = 10240
'''
def newbinsize(ui, repo, node=None, **kwargs):
'''forbid to add binary files over a given size'''
forbid = False
# default limit is …Run Code Online (Sandbox Code Playgroud)