diff --git a/doc/hg.1.txt b/doc/hg.1.txt --- a/doc/hg.1.txt +++ b/doc/hg.1.txt @@ -328,30 +328,48 @@ FILES NAMED REPOSITORIES ------------------ - To give symbolic names to a repository, create a section in .hgrc - or .hg/hgrc containing assignments of names to paths. +To give symbolic names to a repository, create a section in .hgrc +or .hg/hgrc containing assignments of names to paths. Example: - Example: - +----------------- [paths] hg = http://selenic.com/hg tah = http://hg.intevation.org/mercurial-tah/ +----------------- + + +HOOKS +----- + +Mercurial supports a set of 'hook', commands that get automatically +executed by various actions such as starting or finishing a commit. To +specify a hook, simply create an hgrc section like the following: + +----------------- +[hooks] +precommit = echo "this hook gets executed immediately before a commit" +commit = hg export $NODE | mail -s "new commit $NODE" commit-list +----------------- + NON_TRANSPARENT PROXY SUPPORT ----------------------------- - To access a Mercurial repository through a proxy, - create a file $HOME/.hgrc in the following format: +To access a Mercurial repository through a proxy, create a file +$HOME/.hgrc in the following format: +-------------- [http_proxy] host=myproxy:8080 user= passwd= no=,,,... +-------------- - "user","passwd" fields are used for authenticating proxies, - "no" is a comma-separated list of local host names - for which proxy must be bypassed. +"user","passwd" fields are used for authenticating proxies, "no" is a +comma-separated list of local host names for which proxy must be +bypassed. + BUGS ---- diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -371,6 +371,30 @@ class localrepository: if pat.search(f): return True return False + def hook(self, name, **args): + s = self.ui.config("hooks", name) + if s: + self.ui.note("running hook %s: %s\n" % (name, s)) + old = {} + for k, v in args.items(): + k = k.upper() + old[k] = os.environ.get(k, None) + os.environ[k] = v + + r = os.system(s) + + for k, v in old.items(): + if v != None: + os.environ[k] = v + else: + del os.environ[k] + + if r: + self.ui.warn("abort: %s hook failed with status %d!\n" % + (name, r)) + return False + return True + def tags(self): '''return a mapping of tag to node''' if not self.tagscache: @@ -548,6 +572,9 @@ class localrepository: self.ui.status("nothing changed\n") return + if not self.hook("precommit"): + return 1 + p1, p2 = self.dirstate.parents() c1 = self.changelog.read(p1) c2 = self.changelog.read(p2) @@ -603,6 +630,10 @@ class localrepository: text = edittext n = self.changelog.add(mn, new, text, tr, p1, p2, user, date) + + if not self.hook("commit", node=hex(n)): + return 1 + tr.close() self.dirstate.setparents(n) diff --git a/tests/test-hook b/tests/test-hook new file mode 100755 --- /dev/null +++ b/tests/test-hook @@ -0,0 +1,9 @@ +#!/bin/sh -x + +hg init +echo "[hooks]" > .hg/hgrc +echo 'precommit = echo precommit hook' >> .hg/hgrc +echo 'commit = echo commit hook: $NODE' >> .hg/hgrc +echo a > a +hg add a +hg commit -t "test" -u test -d "0 0" diff --git a/tests/test-hook.out b/tests/test-hook.out new file mode 100644 --- /dev/null +++ b/tests/test-hook.out @@ -0,0 +1,9 @@ ++ hg init ++ echo '[hooks]' ++ echo 'precommit = echo precommit hook' ++ echo 'commit = echo commit hook: $NODE' ++ echo a ++ hg add a ++ hg commit -t test -u test -d '0 0' +precommit hook +commit hook: acb14030fe0a21b60322c440ad2d20cf7685a376