문제

I'm attempting to disallow pushes to a Mercurial repository if a certain condition holds true. However, it is essential that if the user uses push --force, the push goes through regardless.

I know that it's easy enough to do this on the machine that's doing the push by using the pre-push hook, which passes in the command line arguments to the hook. However, since hooks aren't propagated, I'd have to somehow distribute the hook to every single user of the repository and rely on them not messing with it.

Therefore, I thought the way to go would be to have a prechangegroup hook on the repository server which checked the condition and aborted the push if necessary, but I can't figure out a way to obtain the command line arguments the user used while pushing from this hook. Is there a way to accomplish this just by using a hook on the repository server?

I know that a possible workaround would be using the pretxnchangegroup hook instead and allowing the push if the commit message of the latest changeset follows a certain pattern. However, the --force option seems much easier from a repository user's perspective, since it wouldn't force them to potentially do a dummy commit to get the message right.

도움이 되었습니까?

해결책

Sorry, the --force command line option isn't ever sent on the wire, so it won't be available on the server side at all. You'll need to figure out some way to signal "I really mean it!" out of band, be it special usernames, special commit messages, or the like.

Consider just having a 2nd server side repo that dosn't have the banning hook and have pushers use it only when they really mean it. Something like:

hg push http://your-server/repo
.. rejected due to hook failure
hg push http://your-server/repo-and-I-really-mean-it

where on the server side the repo-and-I-really-mean-it repo doesn't have the hook and automatically pushes to the plain repo.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top