How do I tell (locally) mercurial that a server is non-publishing?

1k Views Asked by At

How can I tell mercurial that a remote server (originally on bitbucket for example, but they no longer support Mercurial) is non-publishing when I do not have access to the remote .hg/hgrc file?

Background

Recent versions of mercurial has a concept of phases that allow one to keep track of which changesets have been shared (public) and which ones have not (draft). Repository changing operations like rebase are allowed on draft changesets, but not public changesets as others might depend on the latter.

Pushing changesets to a public server will change their phase to public by default, but if the server is private or dedicated to code reviews (i.e. people should not be able to pull), then pushing to that "non-publishing" server should not change the phase.

The documented way of telling mercurial that the server is non-publishing is to add a [phases] section to the .hg/hgrc file on the server:

[phases]
publish = False

It seems to me that there should be a way of including a line in one of my local hgrc files that says a particular server is non-publishing, but I cannot find any documentation to suggest how. Perhaps this behaviour could be customized with a hook?

References

2

There are 2 best solutions below

2
On BEST ANSWER

There is currently no way to do that and it should hopefully never happen.

Here is why:
If you allow the local repository to override the remote repository configuration, you are just making the whole phase mechanism useless. The point of the phases is to prevent user to perform actions that could "corrupt" the synchronization flow.
It the responsibility of the receiver to describe how the received changesets will be used. If you invert that logic, by allowing the sender to override these settings, then, how can you ensure that two senders will use the same configuration? If the configuration differ, which one should be kept? How should the changesets be marked on the receiver?

To some degree, it would be the same as if a local repository was able to push changesets to a remote without being authorized, just by overriding the remote configuration locally.

0
On

I know this question is 10 years old, but just now I had exactly this requirement, a very old Mercurial server, which doesn't even know about phases (all its repos are always publishing), where I wanted to create a review repository.

I found the answer in this old mail thread:

The idea is, you have a public repository (here called <public>), which contains all public commits, and you install pull and push hooks which change all those local commits to draft, that are NOT on this public repo.

[hooks]
post-push = hg phase --force --draft 'public() and outgoing(<public>)'
post-pull = hg phase --force --draft 'public() and outgoing(<public>)'