小编Eri*_* L.的帖子

Mercurial钩子禁止提交大型二进制文件

我希望有一个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)

mercurial hook pre-commit-hook mercurial-hook

10
推荐指数
2
解决办法
2976
查看次数

标签 统计

hook ×1

mercurial ×1

mercurial-hook ×1

pre-commit-hook ×1