在推/拉之前自动触发Hg存储库验证,无需编程

问题描述 投票:3回答:2

我们发现几周前我们的Hg存储库已损坏。这种腐败似乎已经传播:所有克隆(中央存储库和用户存储库)都以同样的方式被破坏,非常糟糕。如果我们当时进行验证,我想我们可以阻止它。

是否有一些Hg设置会导致每次推送验证,并在验证失败时阻止推送?我知道我可以将它作为Python中的钩子实现,但是可能有更简单的解决方案吗?

是否也可以这样做:确保在拉动之前验证远程存储库?

FWIW,我在Windows 10上,我们正在使用TortoiseHg。

更新:我已尝试按照Jordi的建议创建钩子。 Hg现在挂着等待锁。这是我看到的:

c:\Users\username\test-hook>hg init
c:\Users\username\test-hook>cd ..
c:\Users\username>hg clone test-hook test-hook-clone
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

# At this point I edited clone repository settings to include
# [hooks]
# preoutgoing = hg verify
#
# Then I created a test.txt file and "added" it via TortoiseHg context menu.

c:\Users\username\test-hook-clone>hg commit
c:\Users\username\test-hook-clone>hg status

c:\Users\username\test-hook-clone>hg outgoing
comparing with c:\Users\username\test-hook
searching for changes
changeset:   0:a61d33af6cdb
tag:         tip
user:        username
date:        Mon May 06 20:32:54 2019 +0200
summary:     test file added

c:\Users\username\test-hook-clone>hg push -verbose
pushing to c:\Users\username\test-hook
searching for changes
running hook preoutgoing: hg verify
waiting for lock on repository c:\Users\username\test-hook-clone held by process '16840' on host 'LT407233'
mercurial verification
2个回答
4
投票

要回答你的问题,钩子不必用Python编写。在适当的服务器的hgrc(在存储库级别或系统级别),只需设置

[hooks]
preoutgoing = hg verify
preincoming = hg verify

这可能会显着减慢所有拉动和推动操作,但也许您愿意牺牲速度来保证正确性。

当客户端试图从损坏的仓库中提取时,这将导致这样的输出:

$ hg clone http://localhost:9000 sample-repo
requesting all changes
remote: abort: preoutgoing hook exited with status 1

在您的服务器日志中,您应该看到类似的输出

127.0.0.1 - - [18/Apr/2019 12:41:09] "GET /?cmd=batch HTTP/1.1" 200 - x-hgarg-1:cmds=lheads+%3Bknown+nodes%3D x-hgproto-1:0.1 0.2 comp=zstd,zlib,none,bzip2 partial-pull
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
 a@0: broken revlog! (index data/a.i is corrupted)
warning: orphan data file 'data/a.i'
checked 2 changesets with 1 changes to 2 files
1 warnings encountered!
1 integrity errors encountered!
(first damaged changeset appears to be 0)

0
投票

您可以启用服务器端选项以对所有传入内容执行更多验证,只需在服务器上设置server.validate=yes选项即可。

最简单的方法是通过添加以下两行在服务器全局hgrc或存储库.hg/hgrc文件中启用它:

[server]
validate = yes

这是一个服务器选项,但您也可以在客户端上使用它。它也应该验证拉力。

(顺便问一下,你看到了什么样的腐败?)

© www.soinside.com 2019 - 2024. All rights reserved.