Commits

Fredrik Håård  committed 62b2694

1.1.0 - working fully as external hook

  • Participants
  • Parent commits f095b27
  • Tags 1.1.0

Comments (0)

Files changed (4)

 ================================================================
 
 Can be configured in any hgrc (system, user, repo) and trigger for 
-a push (pretxnchangegroup) into any repository that uses that hgrc. 
+any hook into any repository which uses that hgrc. 
 Can load external (Python) hooks that needs to accept parameters 
 repo, user, start revison, end revision
 
   List of tests to run for all repositories
  superuser
   List of users who are allowed to bypass tests
+ selective
+  If set to true, only run for repositorys defined in ``repos`` and
+  with a valid path set through ``<reponame>.path``
  repos
   List of repository names
  <reponame>.path 
   Path to the repository named <reponame>
  <reponame>.tests
-  Tests to run for the repository named <reponame>
+  Tests to run for the repository named <reponame> (in addition to global)
 
 Custom hooks are expected to take five arguments (check the example hook)::
 
  end - last revision pushed
 
 Sample config::
-
+ 
  [hooks]
- pretxnchangegroup = python:path/to/autohook/autohook.py:hook
+ pretxnchangegroup = autohook
 
  [autohook]
- debug=True
  loadpath=/path/to/hooks
- loadmodules=hookmodule1 hookmodule2
- tests = adds_branch hookmodule1.myhook
- repos = orig
- orig.path = /path/to/repo
- orig.tests = has_multiple_heads hookmodule2.hook
+ loadmodules=hookmodule
+ tests = adds_branch hookmodule.myhoo
+
+Installation
+------------
+Easy::
+ pip install autohook
+
+Manual::
+ python setup.py install
+
 
 License
 =======

File autohook/__init__.py

 """
 sample config
 [hooks]
-pretxnchangegroup = python:path/to/autohook/autohook.py:hook
+pretxnchangegroup = autohook
+
 
 [autohook]
 debug=True
 loadpath=/path/to/hooks
-loadmodules=hookmodule1 hookmodule2
-tests = adds_branch hookmodule1.myhook
-repos = orig
-orig.path = /path/to/repo
-orig.tests = has_multiple_heads hookmodule2.hook
-
+loadmodules=hookmodule
+tests = adds_branch hookmodule.myhook
 """ 

File autohook/autohook.py

 # -*- coding: utf-8 -*-
-import os.path, sys
+import os.path, sys, os
 from hgapi import hgapi
 
 def example_hook(repo, user, start, end):
     """Small, stupid example hook that verifies
     that the code is really, really tested. For sure.
     """
-    for rev in xrange(start, end):
+    for rev in xrange(start, end + 1):
+        print 
         if not "TESTED!!!!" in repo[rev].desc:
             print("Abort: Code not tested!\n")
             print("Comment was: %s" % (repo[rev].desc,)) 
     """Check if multiple heads are being added"""
     heads = repo.hg_heads()
     count = 0
-    for rev in xrange(start, end):
+    for rev in xrange(start, end + 1):
         if repo[rev].node in heads:
             count += 1
     print("Found %d heads\n" % (count+1,))
     not share branch with any parent"""
     heads = repo.hg_heads()
     
-    for rev in xrange(start, end):
+    for rev in xrange(start, end + 1):
         revbranch = repo[rev].branch
         one_parent_ok = False
         for parent in repo[rev].parents:
     mod = imp.find_module(name, path)
     globals()[name] = imp.load_module(name, *mod)
 
-
 def _load_modules(repo):
     """Load modules configured in autohook.loadmodules"""
     for module in repo.configlist("autohook", "loadmodules"):
         _load_module(module, repo.configlist("autohook", "loadpath"))
 
     
-def hook(repo, url, node, pending, env):
-    
+def hook(repo, node, pending, env):
+    """Run hooks"""
     def debug(msg): 
         if repo.configbool('autohook', 'debug'): 
             print(msg + "\n")
 
     #Resolve path and see if we should handle this repo
     dest = os.path.abspath(pending)
-    reponame = _get_reponame(repo, dest)
-    if not reponame: 
-        info("Not configured for repo at %s" % (dest,))
-        return False
-    debug("Repo name " + reponame)
+    if not repo.configbool('autohook', 'selective'):
+        repotests = []
+    else:
+        reponame = _get_reponame(repo, dest)
+        if not reponame: 
+            info("Not configured for repo at %s" % (dest,))
+            return False
+        debug("Repo name " + reponame)
+        repotests = repo.configlist('autohook', '%s.tests' % (reponame,))
 
     #Get first and last revision
     start = repo[node].rev
     end = repo['tip'].rev
-        
+
+    debug("Looking at rev %s to %s" % (start, end))
+
     #Run tests, first global and then specific for this repo
-    for test in (repo.configlist('autohook', 'tests') +
-                 repo.configlist('autohook', '%s.tests' % (reponame,))):
+    for test in (repo.configlist('autohook', 'tests') + repotests):
         debug("Running " + test)
         #Resolve nested names
         if "." in test:
     return False
 
 
-if __name__ == "__main__":
-    import os
-
+def main(env=os.environ):
     repo = hgapi.Repo(os.path.abspath(os.curdir))
     node = os.environ['HG_NODE']
-    url = os.environ['HG_URL']
-    pending = os.environ['HG_PENDING']
-    sys.exit(int(hook(repo, url, node, pending, os.environ)))
 
+    if 'HG_PENDING' in os.environ:
+        pending = os.environ['HG_PENDING']
+    elif repo.config('bundle','mainreporoot'):
+        pending = repo.config('bundle','mainreporoot')
+    else:
+        pending = os.path.abspath(".")
+    return int(hook(repo, node, pending, os.environ))
 
 setup(
     name = "autohook",
-    version = "1.0.1",
+    version = "1.1.0",
     packages = ['autohook'],
-    install_requires = ["hgapi>=1.0.0"],
+    install_requires = ["hgapi>=1.0.1"],
     # metadata
     author = u"Fredrik Håård",
     author_email = "fredrik@haard.se",
     license = "Do whatever you want, don't blame me",
     keywords = "mercurial hook api",
     url = "https://bitbucket.org/haard/autohook",
+    entry_points = {
+        'console_scripts': [
+            'autohook = autohook.autohook:main'
+        ]
+    },
     long_description = """
 Can be configured in any hgrc (system, user, repo) and trigger for 
-a push (pretxnchangegroup) into any repository that uses that hgrc. 
+any event into any repository.
 Can load external (Python) hooks that needs to accept parameters 
 repo, user, start revison, end revision