Fryboyter

Hooks under Mercurial

Yesterday I had published an article about the version control Mercurial. The project in question was managed with Git. There were also some hooks present. For example, you can use them to execute commands automatically when a new commit is uploaded. For this you use the hook “post-receive” as I recently described it in an article. Tux also commented that this is also possible with Mercurial.

Absolutely correct in itself, but either the documentation is in need of improvement or I didn’t get it. I assume the latter at this point.

Under https://www.mercurial-scm.org/wiki/Hook the whole thing is described. Every time I add a commit, a hook should be executed. So I entered the following in the configuration file hgrc.

[hooks]
commit = /pfad/zur/Datei/commithook

Under /path/to/file/ I created the commithook file and entered the script that should be executed. Then I made the file executable.

But it didn’t work. The commits arrived, but the hook was not executed. After some Google-Fu I noticed why. The commit hook only seems to work if you commit it directly in the repository. Not if you push it in, though.

Therefore you have to enter the following into the file hgrc.

[hooks]
changegroup = /pfad/zur/Datei/commithook

Herewith the hook is always executed when committing.

OSBN | General

Convert Git to Mercurial

It often happens that someone switches from one version control system to Git. Sometimes, however, someone wants to switch from Git to another solution. Recently I had such a request. Mercurial was wanted.

The relevant git repository was still quite fresh, but there were already commits in the low three-digit range. Too many to create manually in Mercurial.

Which is not necessary. Mercurial offers the possibility to convert.

Let’s assume that the home directory contains the directory repository. In this directory there is the directory blog.git where the Git repository is located.

First you have to create the subdirectory blog.hg in the repository directory and switch to it. There you create a Mercurial repository with “hg init”. This creates the directory .hg. In this directory you create the file hgrc with the following content.

[extensions]
hgext.convert=

This enables the extension with which the conversion can be performed.

Now execute the following command in the directory blog.hg.

hg convert --datesort ~/repository/blog.git ~/repository/blog.hg

It’ll take a while. But if everything goes as planned, you should get a Mercurial repository with all commits, files, etc. as in the Git repository. If you look at the directory blog.hg, you will still only see the subdirectory .hg. The problem can be solved by executing the command “hg update”. If you then look in the directory blog.hg you can also see all the files you originally added to the Git repository.

OSBN | General