How to enforce commit policies in Mercurial DVCS

For a little software development, I would like the changes to fit a specific process, as a result of which the integration branch would contain only “complete” changes. The idea stems from a blog post about getting useful history magazines from Mercurial. However, this is not only about creating magazines, but also about a structured way of working.

In general, the idea is that there will be an “integration” branch in the repository that will not directly develop, instead, any work will be performed on another branch, and when the full one is merged into the integration branch - below is an example with comments in braces:

O {Implemented new feature X} |\ | O {...} | | | O {...} |/ O {Fixed bug 002} |\ | O {...} |/ O {added tag "Release 1.0"} | O {Fixed bug 001} |\ | O {...} |/ O -- integration branch / O -- default branch 

An “integration” branch could only come together and tag.

This is similar to how we work on development (on a server system other than DVCS), where you make changes to your work branch, and when you complete (and check, check, ...), you merge these changes into a branch integration, for formal testing and release.

In any case, my question is: how should I apply the policy of making changes only to the work branch, and on the integration branch we only allow merging or tagging?

My initial thought was to add a hook to pre-commit ( not precommit or pretxncommit , since I believe that they fire when you, for example, create a tag). The hook will verify that if you were on an integration branch, there are two parents, that is, it is the result of a merge, and it fails if it is not.

However, as I understand it, hooks are not copied when cloning a repository. Since this will be a project-specific parameter, it should not be set at the user level. So, how can I prevent a user from cloning a repository (thus losing hooks) by making changes directly to the integration branch and then clicking?

 hg clone main_repo hg update integration_branch (make changes without starting a new branch) hg commit -m "I made some changes" hg push 

Also, how can I apply this when using a system like Bitbucket?

Alternatively, is this not the right approach to workflow when using DVCS?

+4
source share
2 answers

I think you said you want a “structured way of working,” and so I wonder if what you are looking for is code lieutenants. This means that the door is locked from the inside, and only the lieutenant opens it, and the code gets to the central repo only when the lieutenant pulls it in. The code that went through your approval process is pulled into a central or authoritative repository, which is a "structured way of working."

Speaking about refusing to write to branches only in the repo, instead of denying the entry to the entire central repo, it sounds to me almost the same way you ask how you can cancel the excellent attribute DVCS # 1, which (a) doesn’t one copy, and that each copy can have its own read / write access rules, one of these copies is central, if you like it, and (b) who commit, are separate from overlaying them on someone else. The end is the action of the local working copy. Only after these commits get into an authoritative repository, either central or the one managed by your lietenant code, did you even make real changes to this controlled process using DVCS.

Or do you think that users should not even make their own local local DVCS servers without creating branches?

In short, we can say that each local machine working copy of IS THE BRANCH, an invisible branch that is not applied to anyone or even named, until it is interrogated by a lieutenant who will review the code, and the integration will check the full set of changes, which is functionally equivalent to that what you might call a "feature branch" in CVCS. These invisible branches are writable, and the central repo (and not a branch, a separate REPO) is read only by virtue of how it is configured; users can synchronize it, but not click on it, except for the lieutenant who makes new changes to it. Fundamentally stable, but still everyone can get a job.

+2
source

If you have access to the central hgrc repo, you can define a pretxnchangegroup that checks that the incoming changes in the integration branch have 2 parents (while the first should be on the integration branch). AFAIK, on ​​Bitbucket you can set up post checks with brokers . These brokers do not prevent unwanted shocks, but can notify you if someone does not follow the rules.

However, I personally am @Zhehao's second comment, that is, just try to get everyone to follow the rules and allow those who violate them to serve coffee to colleagues for one week (or so, you will receive it).

Finally, you can save some common hgrc and corresponding interceptors that each developer must install (once) on his system. If installed globally in the system, there is no need to install them again for each clone.

+1
source

All Articles