I have created a post-clone hook in .hg/hgrc. This hook sometimes executed, and sometimes not, depending on which directory hg is called from.
Let the repository be in /path/to/repos/. The post-clone hook is in /path/to/repos/.hg/hgrc.
Cloning from /path/to/repos/, the post-clone hook is executed:
$ pwd
/path/to/repos/
$ hg clone ./ /path/to/myclone/
Cloning from /path/to, the post-clone hook is not executed:
$ pwd
/path/to/
$ hg clone repos myclone
Why is the hgrc in my repository not read/post-clone hook not executed in the latter case?
Regards,
Freddy
I suspect you need to put the hook in your ~/hgrc file, rather than your repo's hgrc.
Hooks do not propagate
i.e.. if you add hook to a repo, then clone the repo, don't expect the hook to be in the new clone.
Here's the main text linked-to from Tom's answer, in case that page eventually changes or goes away:
Hooks do not propagate
In Mercurial, hooks are not revision controlled, and do not propagate
when you clone, or pull from, a repository. The reason for this is
simple: a hook is a completely arbitrary piece of executable code. It
runs under your user identity, with your privilege level, on your
machine.
It would be extremely reckless for any distributed revision control
system to implement revision-controlled hooks, as this would offer an
easily exploitable way to subvert the accounts of users of the
revision control system.
Since Mercurial does not propagate hooks, if you are collaborating
with other people on a common project, you should not assume that they
are using the same Mercurial hooks as you are, or that theirs are
correctly configured. You should document the hooks you expect people
to use.
In a corporate intranet, this is somewhat easier to control, as you
can for example provide a “standard” installation of Mercurial on an
NFS filesystem, and use a site-wide ~/.hgrc file to define hooks that
all users will see. However, this too has its limits...
That last warning may have been referring to the very next section which adds:
If you deploy a system- or site-wide ~/.hgrc file that defines some
hooks, you should thus understand that your users can disable or
override those hooks.
Related
We have some restrictions on what we are allowed to put in our central Mercurial repository.
Is there some way I can keep stuff in my local Hg repository, without having it pushed to the central one?
Note:
The files might be connected to files in the central repository (branches for example).
Local stuff might later be incorporated in the central repository.
If you're using branches, you can set their visibility to secret. This will prevent them to be pushed.
hg phase --secret --force my-branch
When you want to share, you change their phase to draft and then they will be automatically collected during a push operation.
See hg help phases for more information.
You could also use Mercurial Queues. With MQ, you can work with patches (which are changesets) and update or re-order them based on changes in the official repository. This will also make it easier to incorporate some or all of your changes into the main repository or just discard them later.
Commit to your local repo, then push to the remote repo when you are finished.
You can push to your local repo as well, but from my understanding that is where your current development is?
I think you want Shelve Extension or Attic Extension.
The other option is if your using a newer Hg with better branching you can just fork the central repo somewhere like bitbucket and use that as your repository for your temporary stuff and potentially branch that.
Finally you could also just use .hgignore but that could be problematic later when someone does check in the file with the same name.
We have an hgrc file that contains settings that should be global to all members of our development team. When I make changes to my hgrc file I do not appear to be able to have these changes propagate to anybody else who clones a repo.
Is there a way to keep these configs global to any user of the repo?
Repo track thyself!
$REPO/.hg/hgrc is not tracked by Mercurial. This is by design for security reason.
You can commit template and create project policy that require setting several setting to $REPO/.hg/hgrc or add to build scripts helper target to deploy template to $REPO/.hg.
I recommend use precommit hooks on central server to ensue that all changes are good. Look to
https://www.mercurial-scm.org/wiki/HookExamples
http://hg.python.org/hooks/ -hooks from Python project.
Note that some files Mercurial treated as special, for example $REPO/.hgignore or .hgeol for EOL plug-in. These files you can commit, so they are easy sharing in dev team.
in order to bypass the JIRA-mercurial plugin, I need to replicate my (private) mercurial repository in a private mercurial repository in bitbucket. I and the other users will continue to "push" our commits to our own private repository, but I want pushed commits to be "forwarded" to a certain bitbucket repository. This way, I can use the JIRA's bitbucket plugin and see the changes related to my bugs.
In other words, I want that, after each push in my private mercurial repository, the commits are forwarded to my repository hosted by bitbucket. I think I should create a push hook, but I never used them before...
I think that the following hook (installed on my server) solves my problem...
[hooks]
changegroup = hg push ssh://hg#bitbucket.org/path/to/my/repository
(Pls, move it into comment of Matteo answer)
changegroup isn't correct type of hook for this task, because
The changegroup hook is activated once for each push/pull/unbundle,
unlike the commit hook, which is run once for each changeset
according to docs, and I suppose, more right way is
[hooks]
commit =
Depending on what mercurial client you are using, there are a number of different ways to have your local repository "push after commit".
The TortoiseHg windows client allows you to configure this per-repository for all commits (under the "settings->commit" dialog), as well as for individual commits under the "options" menu when committing.
There are also hook scripts that you can use. A quick google search finds many different options.
What are all steps required to validate commit message with set of regular expressions?
We want to work in semi-centralized set-up so I need a solution for the developer clone (local repository) and for our central clone (global repository). I read about Mercurial Hooks but I am a little bit lost how to put all things together.
For local repository I need a way to distribute validation script across my developers. I know that hooks do not propagate when cloning so I need to a way to "enable" them in each fresh clone. It would be done as a part of our PrepareEnvironement.bat script that we run anyway on each clean clone.
To be double safe I need similar validation on my global repository. It should not be possible to push into global repository commit that are not validating. I can configure it manually - it is one time job.
I am on Windows so installing anything except TortoiseHG should not be required. It was already a fight to get Mercurial deployed. Any other dependencies are not welcomed.
You can use the Spellcheck example as a starting point. In each developer's configuration, you need to use the following hooks:
pretxnchangegroup - Runs after a group of changesets has been brought into local from another repository, but before it becomes permanent.
pretxncommit - Runs after a new changeset has been created in local, but before it becomes permanent.
For the centralized repo, I think you only need the pretxnchangegroup hook unless commits can happen on the server, too. However, you will need the Histedit extension for each of the developers if the remote repo is the one rejecting one or more of the changesets being pushed. This extension allows them to "edit" already committed changesets. I would think in most cases, the local hooks will catch the issue, but like you said, "just in case."
More details about handling events with hooks can be found in the Hg Book.
I have a server which hosts a mercurial repository with hgwebdir. Is it possible to make mercurial to run a script when someone pushes to this repository?
Currently I use a script that checks the repository state every few minutes, but this is obviously an ugly solution.
You have to add a hook to your Mercurial server:
Edit .hg/hgrc (or mercurial.ini on Windows)
Add or edit the [hooks] section
Associate a shell command to the hook you are interested in (in your case, the changegroup hook)
Look at Handling repository events with hooks in the Mercurial red-bean book for more details.
You might want to take a look at mercurial hooks,
http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html