Common HgNotify template configuration - mercurial

Is there a way to point to a common HgNotify configuration in each repositories' hgrc file on windows? I have the below notify section in each hgrc for every repo that I have on the server, and when I want to create a new repo, I have to copy this section into the hgrc.
[notify]
sources = serve push pull bundle
#For template, see: http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
strip=3
template =
files:
{files}
details: {baseurl}/rev/{node|short}
branches: {branches}
changeset: {rev}:{node|short}
user: {author}
date: {date|date}
description:
{desc}
=================\n
test=false
maxdiff = 0
config=D:\hg\Repositories\HgNotify\NotificationList.txt
I am experimenting with changing the template and would like all repos to get the new template automatically.
Update: The Hg server is on windows and served thru IIS.

You can use a global hgrc file with settings for all repositories. See man hgrc.

I ended up using the %include syntax for an hgrc file, in part because the server is a Windows box and I was not sure where to put a global hgrc file that could be accessed by the IIS server/IIS user.
I put the following at the end of my hgrc files:
%include D:\Hg\HgNotify\hgrc.notify.txt
The %include actually works out great because it allowed me to put the file in an hg repo of its own so that I can have a history of changes made.
Here's what a complete hgrc file looks like in one of my repos:
[web]
name=MyRepo
contact=hg#mydomain.com
push_ssl=False
description=MyRepo
allow_archive = zip
allow_push = *
baseurl = http://hg.mydomain.net/MyRepo
logourl = http://hg.mydomain.net/
[extensions]
hgext.notify =
progress =
rebase =
[hooks]
changegroup.notify = python:hgext.notify.hook
#Include file for common notification template
%include D:\Hg\HgNotify\hgrc.notify.txt

Related

Mercurial, define my own template/keyword: hostname

I need a mercurail template/keyword "hostname" to get the name (or IP) of the computer where the repo is located. as far as i read the wiki, namely "Chapter 11. Customizing the output of Mercurial", hg help templates, and the web, I think it should be similar to the date keyword, dynamicly expanded. How can i define my own template/keyword?
Thank you verry much
The following extension should do the trick:
from mercurial import templatekw
testedwith = "3.5"
_ipname = None
def showipname(repo, ctx, templ, **args):
""":ipname: String. The hostname of the machine that the repository
resides on."""
import socket
global _ipname
if not _ipname:
_ipname = socket.gethostname()
return _ipname
def uisetup(ui):
templatekw.keywords["ipname"] = showipname
Then use (say):
hg log -r . -T '{node|short} at {ipname}\n'
Note that the value of socket.gethostname() may depend on your internet connectivity. If you need the value in /etc/hostname or something else that identifies your machine, use that method instead.
To use an extension, put it in a file, say ipnametempl.py somewhere, then add the following lines to your .hgrc:
[extensions]
ipnametempl=/path/to/ipnametempl.py
This can be either your user/global hgrc or the .hg/hgrc in your repository (the latter if you only want to enable it for a specific repository). See hg help hgrc to find out where the user/global hgrc files are on your system.
Either the repository is local to your machine (then you can get the absolute path via hg root) and query the name via the normal system tools. You can embed those also in your templates:
$ hg log -r. --template="{branch}-{rev} from $(hostname) running debian $(cat /etc/debian_version)"
trunk-22248 from MYHOSTNAME running debian 8.2
Or you know already the URL (remote path) in order to operate with it as you need to specify it as argument to hg pull/clone/outgoing/incoming
If the remote URL is not explicitly specified on the command line it is specified in your .hgrc in the [path] section. When there is a remote repository at all, then usually a default = URL is defined there.
If you need the URL printed, then install hooks for clone, pull and push (and maybe outgoing and incoming) which prints the $URL as available in those hooks - or maybe just the changegroup hook. Check http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#sec:hook:changegroup and hg help config.

tortoise hg : how to get notified whe something pushed to a central repo

i am using Mercurial for version control. One central repo is shared among the team and any of us can push / pull to it.
How can i get notified when any other user push something to the central repo.
I have tried to edit my hgrc file as per the https://www.mercurial-scm.org/wiki/NotifyExtension
as below
[extensions]
hgext.notify =
[hooks]
# Enable either changegroup or incoming.
# changegroup will send one email for each push,
# whereas incoming sends one email per changeset.
changegroup.notify = python:hgext.notify.hook
#incoming.notify = python:hgext.notify.hook
[email]
from = **myemailaddresshere**
[smtp]
host = localhost
# presently it is necessary to specify the baseurl for the notify
# extension to work. It can be a dummy value if your repo isn't
# available via http
[web]
baseurl = **http://repoip:port/**
[notify]
# multiple sources can be specified as a whitespace separated list
sources = serve push pull bundle
# set this to False when you're ready for mail to start sending
test = True
[reposubs]
* = **toemailaddresshere**
#config = /path/to/subscription/file
# you can override the changeset template here, if you want.
# If it doesn't start with \n it may confuse the email parser.
# here's an example that makes the changeset template look more like hg log:
template = \ndetails: {baseurl}{webroot}/rev/{node|short}\nchangeset: {rev}:{node|short}\nuser: {author}\ndate: {date|date}\ndescription:\n{desc}\n
maxdiff = 300 # max lines of diffs to include (0=none, -1=all)
then i tried to push sme changes . But this didnt fire any email.
Can you please check what is error in my .hgrc file
Your Notify extension is configured to be in test mode. Maybe setting test = False will help?
template and maxdiff should be in the [notify] section. In your sample, they are in the [reposubs] section.
You can use hg help to check if the notify extension is enabled.

Mercurial does not send emails using changenotify

I set up a http central Mercurial repository and try to send emails on every push. I follow instructions from mercurial page and from http://morecode.wordpress.com/2007/08/03/setting-up-mercurial-to-e-mail-on-a-commit/.
Push works fine, but I don't see any notify message at all. Please help me.
My .hg/hgrc in my repository folder of my client looks like this
[extensions]
hgext.notify=
[hooks]
changegroup.notify = python:hgext.notify.hook
[email]
from = what#gmail.com
[smtp]
host = smtp.gmail.com
username = what#gmail.com
password = ohyea
port = 587
tls = true
[web]
baseurl = http://1.1.1.1/repo_name
[notify]
sources = serve push pull bundle
# set this to False when you're ready for mail to start sending
test = False
config = /home/myhome/something/subscription.conf
template = \ndetails: {baseurl}{webroot}/rev/{node|short}\nchangeset:{rev}:node|short}\nuser: {author}\ndate: {date|date}\ndescription:\n{desc}\n
maxdiff = 300
My /home/myhome/something/subscription.conf looks like
[reposubs]
# key is glob pattern, value is comma-separated list of subscriber emails
* = sometestemail#gmail.com
I save and my result looks like below, if you notice I don't see any notify message at all
pushing to http://1.1.1.1/repo_name
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 2 changesets with 7376 changes to 7376 files
[Update:]
I found that there was no hgext folder in my system. So I manually downloaded the source matching my hg version and updated my hgrc as below, and still it does not work. Any help please.
[extensions]
notify= /path/to/notify.py
[Update 2:]
Thanks Ry4an - I tried it, still no luck.
In my webserver
Under /var/www and /var/www/hg
I created .hgrc files, just not sure which one is my webroot, so I did at both places with contents
[trusted]
users=user_name
this user name is the username in my client from where I'm trying to push to the repo.
on my client
in the .hg/hgrc of my repo, I added trusted section
[trusted]
users=user_name
The above procedure did not help
Second approach
on my client,
under my repo's .hg, I did
chown www-data:www-data hgrc
and when I tried to push I got some message while pushing saying
sending capabilities command
capabilities: changegroupsubset stream lookup pushkey unbundle=HG10GZ,HG10BZ,HG10UN branchmap
sending heads command
searching for changes
common changesets up to 6ef19c49143a
sending branchmap command
ignoring untrusted configuration option hooks.changegroup.notify = python:hgext.notify.hook
This ignoring command does not appear during the first approach, only after I change the ownership of hgrc, this pops up.
It's likely a trust issue, but let's hit a few other things first:
A) Switch the extension load to:
[extensions]
notify=
The hgext part is no longer necessary, but doesn't hurt. Giving the full path to the extension is more fragile in the case of future updates. The raw notify= syntax is sufficient for extensions that come with Mercurial and notify always does.
B) Switch the test = false to test = true it will help you debug this -- it sends the email to Stdout, which is handy.
Okay, those two done, let's look at trust. Mercurial's trust system is built around the idea that not just anyone should be able to get you to run code. Imagine if your repo's .hg/hgrc file had a section in it like:
[hooks]
pre-push = rm -rf ~
When I pushed to it it would delete my home directory. That would bum me out. To avoid that happening Mercurial will only load/run hgrc files that it trusts, and you tell it what to trust with [trusted] sections in your hgrc. When you're pushing over ssh you're effectively logging into the remote machine and it's your own ~/.hgrc that probably states what other hgrc files you're willing to execute.
HTTP is special though. Even though you may be authenticating you're probably not running Mercurial on the remote system as yourself. It's probably some some non-user user like www-data, www, apache, or noone depending on how your web server is configured, so... you need to make that repo's .hg/hgrc' owned (or group-owned) by an user (or group) that the webserver user trusts. To achieve that you can eitherchwownthe.hg/hgrcfile over to the web server user, or find the web server's home directory (often/var/www) and create a.hgrcfile in there with a[trusted]block saying that the web server user trusts whomever it is that owns the repo's.hg/hgrc` file.
If I'm right about what's going on the tell tale sign would be in your webserver's errors log where you'd see a lot of messages like "Not trusting /path/to/repo/.hg/hgrc owned by someuser".
TL;DR: Make sure your web server user trusts (in the hgrc sense) the owner of the .hg/hgrc that's specifying the hook.
This worked for me when communicating with an Exchange Server:
[hostfingerprints]
<my exchange FQDN> = 2a:f3:89:69:13:b2:1e:3a:c2:fe:f9:7f:de:b3:39:e7:82:8e:99:93
[extensions]
notify =
[hooks]
changegroup.notify = python:hgext.notify.hook
[email]
from = Mercurial Notification <noreply#mydomain>
[smtp]
host = <exchange FQDN>
tls = true
[notify]
sources = serve push pull bundle
test = False
maxdiff = 300
[reposubs]
* = Cameron Rich <cameron.rich#mydomain.com>
Put the above in the hgrc file in your repository.
e.g. C:\repositories\test.hg\hgrc

Problem with loading hggit extension in TortoiseHG

I'm trying to get the hggit extension to work under Windows 7 (64bit) using TortoiseHG (2.1.2). I followed the official setup instructions, i.e. cloning the hg-git repository and adding the "hggit = ..." line to the extensions section in my mercurial.ini file.
However the extension doesn't seem to be loaded. When trying to clone a repository I get the following error :
abort: repository git://... not found!
running
hg help hggit
results in
hg: unknown command 'hggit'
I also don't get any errors at all, no matter what I put in the extensions section of the mercurial.ini file.
Any ideas on what the problem might be ? Are there any log files at all that show me whether there are problems loading the extensions ?
Had the same problem, and in my case I forgot to specify the [extensions] line in the INI file.
Not working:
[ui]
username = My name <my#emailaddress.com>
hgsubversion=D:\Repotools\hg-svn\hgsubversion
hggit=D:\Repotools\hg-git\hggit
Working:
[ui]
username = My name <my#emailaddress.com>
[extensions]
hgsubversion=D:\Repotools\hg-svn\hgsubversion
hggit=D:\Repotools\hg-git\hggit
When you run the command hg help hggit it will report if the directory path is incorrect.
You should include what you have after hggit =
It should be pointing to the hggit subdirectory in the directory you cloned the repository into.
e.g. hggit=C:\hg-extensions\hg-git\hggit

how can you configure tortoisehg to see in the web servers page the "graph" link?

In the mercurial repo i can see it.
I think that mercurial already have this feature with the revision graph.
How i've to configure tortoisehg to achieve that?
I want to have something like this for the hgweb.
Tortisehg doesn't have a built-in graph viewer, but it will call off to 'hg view' or 'hgk' if they're installed and you have your tortoisehg.view configured in your Mercurial.ini file.
From http://tortoisehg.wiki.sourceforge.net/FAQ:
Q: How can I add hgk (hg view) back to TortoiseHg-0.3?
A: Download tclkit and place it in your TortoiseHg directory. Download the hgk script from the Mercurial repository and place it in your TortoiseHg\contrib directory. Create an hgk.cmd file and place it in TortoiseHg\scripts. This file should contain:
#set HG=C:\Program Files\TortoiseHg\hg.exe
#"C:\Program Files\TortoiseHg\tclkit-win32.exe" "C:\Program Files\TortoiseHg\contrib\hgk" %*
Then enable hgk in your Mercurial.ini file:
[extensions]
hgext.hgk =
[hgk]
path=C:\Program Files\TortoiseHg\scripts\hgk.cmd
vdiff=vdiff
Then tell TortoiseHg to use hgk as your external log viewer in your Mercurial.ini file. This will enable the 'Revision Graph' entry in the context menu and
cause it to launch hgk. The 'View Changelog' menu entry will still launch TortoiseHg's changelog viewer.
[tortoisehg]
view = hgk