Adding hooks to TortoiseHg - mercurial

I am using TortoiseHg and would like to apply a hook to my repo. My repo's .hg/hgrc file is as follows:
[hooks]
pretxncommit = python:hg_checksize.newbinsize
The thing is that I don't know where TortoiseHg's PYTHONPATH variable is set. How do I change it? Or where do I put my Python file so that it is visible by TortoiseHg's Python interpreter?
I cannot find any mention of hooks in TortoiseHg's documentation or through Google?

you can put your .py wherever you like and use a full path to it. the syntax is then
[hooks]
pretxncommit.myhook = python:/path/to/my.py:newbinsize

To enable in-process hooks in TortoiseHg you must put your *.py file into C:\Program Files\TortoiseHg\library.zip. TortoiseHg loads Python files from library.zip.
Reinstalling TortoiseHg will probably mean having to repeat this step.

jk's answer is correct, according to hekevintran's comment he has a typo. It should be
pretxncommit.myhook = python:C:\src\hooks\hg_checksize:newbinsize
it should be a colon between python-file and method, not a period
(confirmed with hg 1.5.1 on Win7)

Related

Detect is file is versioned

For example I have a hg versioned project in this path: C:\src\sample_project
Now, lets this project have subfolders, and lets say I'm editing a file inside this project C:\src\sample_project\docs\index.rst.
Having the path of this file C:\src\sample_project\docs\index.rst what is the easiest and most effective way to check if the file is versioned by hg, by either using Windows shell commands, hg.exe or tortoise (thg.exe)?
I'll post my doubt as answer.
Command to check if file is versioned: hg status <path> and then if the first character in stdout of this command is ? or a (from abort: no repository found in...) I should assume that file is not versioned.
What you stated is a way, but there is a cleaner one imo. You can use:
hg status -u which lists all unknown (read: not tracked) files in your repository.

Can I set Mercurial config options programmatically?

I'm looking for a way to set .hgrc configuration items without actually editing the text file. I'm trying to standardize the setup of the hgrc across multiple developers and I would like a command like
hg --config ui.username=foo
but which also saves that config change into the hgrc file.
It seems like this should be something that should be supported directly in the vanilla hg command, but I can't find it anywhere.
Someone -- either you or Mercurial -- will have to edit the configuration file if you want the config change to be saved :-)
And if you can call Mercurial with
hg --config ui.username=foo
then you should also be able to do
echo '[ui]' >> ~/.hgrc
echo 'username = foo' >> ~/.hgrc
which will save the config change, not matter how the ~/.hgrc file happens to look like (it is okay to have multiple [ui] sections).
Mercurial 3.0 and later has the hg config --edit command that opens an editor with the user config file. Still not quite what you're asking for, but at least this makes it easier to edit the file interactively.
This form:
hg --config ui.username=foo
Doesn't save anything. It sets the value for just the one run.
Also you can use /etc/mercurial/hgrc for system wide settings if that helps anything.
There is an extension that helps with this, https://bitbucket.org/alu/hgconfig/wiki/Home
After installing that hgext, you can do things like this.
% hg showconfig paths
paths.default=ssh://hg#bitbucket.org/alu/hgconfig
% hg config paths.upstream $(hg showconfig paths.default)
% hg config paths.default $(hg showconfig paths.default | sed 's|/alu/|/nassrat/|')
% hg showconfig paths
paths.default=ssh://hg#bitbucket.org/nassrat/hgconfig
paths.upstream=ssh://hg#bitbucket.org/alu/hgconfig
The only gotcha is this overrides the builtin config command, you can either tweak the code to change the command name, or live with it. Fortunately, it probably would not matter if your use case is simply to set and get specific configs.

Mercurial - How to remove a file from version control?

So I accidentally included a config file (different for each machine) into our mercurial repositories.
How can I get Mercurial to not include it in version control? I don't want to delete the file since I still want it. And I don't want to cause the file to get deleted on other developer's working directories either.
And how do I do this in TortoiseHG?
Right click on the file -> TortoiseHG -> Forget Files. Click Forget. Commit and Sync.
Edit:
You'll also want to add the path to your .hgignore to keep it from getting added again. You can right click on the file in the HG Commit dialog and choose to ignore it.
Here's the manual way of doing it through the command line:
Copy the config file somewhere outside of the repository.
Run hg rm path/to/config/file
Add the config file path to your .hgignore.
Commit the repository.
Move the config file back to where you had it.
Do an hg stat on your repository to double check you did everything right. (It shouldn't show up in the list of modified/added files).
Edit:
hg forget is the best way to do this.
Run hg forget path/to/config/file
Edit your .hgignore and add the path to the config file.
hg ci to save your changes.
Run hg stat to ensure everything worked according to plan.
See nates answer for how to do it TortoiseHG.
hg remove or hg remove -f?
I think hg forget also removes it from the branch.
In both cases, files are retained in your directory.
For those using SourceTree, there is an option Stop Tracking when you right click a file, it basically does the same thing as hg forget or git rm --cache, removing the file from repo but not from hard disk.
add it to your ignore list.
See the .hgignore file.
TortoiseHG gives you access to this config file via the "Edit Ignore Filter" menu option.

hg: unknown command 'qimportbz'

I followed the instructions on how to setup qimportbz here; I'm on WinXP and instead of adding:
[extensions]
qimportbz = C:\mozilla\mercurial\qimportbz
to a .hgrc file I updated a Mercurial.ini file which seems to be the correct file to add extensions to for me..
then when I run hg help qimportbz I see the help for the qimportbz cmd, but when I try to run hg qimportbz 548590 for example, on the jetpack-sdk hg repo, I get the following error:
hg: unknown command 'qimportbz'
I had this problem. I believe the syntax has changed. Try hg qimport bz://bug_num where bug_num is the bugzilla bug id.
Try instead to declare the extension in your <repo>/.hg/hgrc file, just to check if that has any influence on the issue.
What does your hg debugconfig show? Any mention of qmimportbz? There's a chance you need double backslashes each time you use them, but the output of debugconfig should make that clear if it's the case.
FWIW either .hgrc or Mercurial.ini will work for you. On unix-alikes only .hgrc is checked, but on Windows both are. See the hgrc man page for details on that.

TortoiseHg Apply a Patch

TortoiseHg allows you to email a patch file of your changes to someone, but does it support applying patches?
If so, how do you apply a patch using TortoiseHg?
From Repository Explorer, Repository > Import...
It looks like there is no built-in support in TortoiseHg for this. Try this from a command prompt:
hg import my-patch-file.patch
That should apply the patch to your Mercurial repo and working copy.
First Stab Answer
You should be able to right-click on the patch file and choose "Apply patch..." - that's how it works for other TortoiseX clients. Make sure that you save the patch file to the same directory path it was generated from.
Downloading TortoiseHg 0.8.1 to test...
What may be also noteworthy is, that "Repository Explorer, Synchronize > Import..." (which internally does a "hg import") will automatically do a "commit" - this may not be always wanted behaviour.
Other possibility is to use unix "patch" command (on Windows perhaps use cygwin version) or use "hg import" directly with "--no-commit" option. Both will just make changes in working directory and you may review the changes and commit them later manually.
In 1.0, from Workbench:
Repository > Import...