I wonder if it is possible in TortoisHG, like in TortoiseSVN, to check if a commit message includes an issue id?
In TortoiseSVN you could set the bugtraq properties on the repo to make a dialog box pop up and warn if an id was not included, and I am looking for a way to do the same thing (still need it to be possible to check in, just show a warning that id is not included and be able to abort the commit if you want to).
Thanks in advance
Jonas H.
As far as I know, nothing like that is possible directly in TortoiseHG.
But TortoiseHG is only a GUI for Mercurial, and in Mercurial, you can do stuff like that with hooks.
See chapter 10 in the HG book for a general desription of what hooks are and how they work:
Handling repository events with hooks
There is even a specific example in this chapter that rolls back a commit if it doesn't contain a bug id.
This dialog in TortoiseHg 2.4's settings looks like what you want:
I only know about the setting issue.linkmandatory = True which forces entry of an issue reference specified in issue.regex and issue.link on every commit.
Related
When I update to different branches in my repo, sometimes the following message is displayed:
note: using 1e30cc4025a0 as ancestor of b9356a6d7187 and 2c4e2c777abe
alternatively, use --config merge.preferancestor=0275bcbb14e5
I found this message to originate from the new BidMerge feature in Mercurial 3.0, but I don't understand why it's showing up on a simple branch change operation. Also, when I add merge.preferancestor=* to my hgrc file, it does not suppress the message. Can anyone explain what's going on?
I have a hook written for Mercurial. It uses the pretxncommit to make sure that the user includes an 'issue number' in their commit message. But sometimes the user may use the 'hg tag' command instead of commit. In this case the user does not need to input an issue number.
How can I tell when the user is making a tag instead of a commit??? Here are a couple places I have searched for the answer but am I missing something or does the documentation just not go that far in depth.
https://www.mercurial-scm.org/wiki/MercurialApi
http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html
How can I tell when the user is making a tag instead of a commit???
Making tag is commit
Clean tagging commit affect only .hgtags file (and add one line to this file)
HTH
I'm a complete noob at Mercurial API and Python, but I'm trying to write a useful extension for myself and my colleagues now.
Let's assume I have a repository which contains some code and an auxiliary file .hgdata. The code and .hgdata are both under Mercurial's control. When I execute a command pull-extended which is provided by my extension, I want it to make a pull and then to analyze the state of a .hgdata and probably make some additional actions. The problem is that when my command is invoked, it just pulls the incoming changesets, but it can't look into the actual .hgdata without making a preceding repository update. Is there any way to watch the after update .hgdata besides repository update?
I've received an answer on the Mercurial's official IRC channel:
In order to get an actual file state after making a pull, we may use repo[revision][file].data().
P.S. I haven't checked that yet. If it works, I will close the question.
When I create a new repository, I can ask TortoiseHG to give me a .hgignore file. Is there a way that I can customise what that file will look like, rather than having to go and get one manually from somewhere every time?
It's an old question, put still popped up as the first result on google, so here is an update:
In the TortoiseHg settings under the tab TortoiseHg users can specify the path of a Repo Skeleton. You can put your predefined .hgignore there, and it will be automatically copied during hg init.
See also:
#3569 Allow user-defined default .hgignore file when creating a new repository
TortoiseHG Docs
Like Tim already said in his comment, apparently it's not possible to do this.
Take a look at the following issue from TortoiseHG's bug tracker:
#966 Include some reasonable defaults in .hgignore on repo creation
Quotes from this link, both by Steve Borho (THG project lead):
This topic comes up on the Mercurial mailing list once a year or so and Matt always shoots it down. There is already support for user level ignore files; one could add these globs to a global file and be done with it.
and:
If a user has files or directories that they always want to ignore, they can add those to a global ignore file without having to introduce any new behaviors in THG.
So putting the things you always want ignored in a user-global ignore file seems to be the only option (even though it's not exactly what you're asking for):
Would like to create some defaults for my .hgignore files in TortoiseHG/Mercurial
(the question that I posted in my comment above)
Global hgignore usage
I have a "central" repository that I want to ensure that no one pushes changes in to with a wrong user name.
But I can not figure out how to make a hook that tests the user name against a positive list. I have found in the Mercurial API a ctx.user() call that seems to be what I want to test my positive list against.
Also the hook could be a precommit hook that is distributed as part of the repository clone or it could be a hook on the central repository as a pre-incoming or something like that.
Any help or pointers would be greatly appreciated.
I have posted two functional examples on Bitbucket. Both examples are for searching a commit message for some specifically formatted text (like an issue tracked case ID), but could be easily modified to check a user against a list of valid users.
The first example is actually a Mercurial extension that wraps the 'commit' command. If it fails to find the appropriate text (or valid user in your case), it will prevent the commit from occurring at all. You can enable this in your .hgrc file by adding these lines:
[extensions]
someName = path/to/script/commit-msg-check.py
The second example uses a in-process pretxncommit hook, which runs between when the commit has been made, but before it becomes permanent. If this check fails it will automatically roll back the commit. You can enable this in your .hgrc file by adding these lines (assuming you kept the same file/function names):
[hooks]
pretxncommit.example = python:commit-msg-check-hook.CheckForIssueRecord
You can execute any Python code you like inside of these hooks, so user validation could be done in many ways.
Thanks for the examples dls.
In the end I decided to run it as a pretxnchangegroup hook and then use the hg log and grep to test the author field of the commits:
[hooks]
pretxnchangegroup.usercheck = hg log --template '{author}\n' -r \
$HG_NODE: | grep -qe 'user1\|user2\|etc'
It does of course not provide a very good feedback other than usercheck failed. But I think it is good enough for now.