summaryrefslogtreecommitdiff
path: root/etckeeper-bzr.py
diff options
context:
space:
mode:
Diffstat (limited to 'etckeeper-bzr.py')
-rwxr-xr-x[-rw-r--r--]etckeeper-bzr.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/etckeeper-bzr.py b/etckeeper-bzr.py
index 4a51085..97a8689 100644..100755
--- a/etckeeper-bzr.py
+++ b/etckeeper-bzr.py
@@ -1,28 +1,26 @@
#!/usr/bin/python
-# bzr plugin that runs etckeeper pre-commit when necessary
+# Bazaar plugin that runs etckeeper pre-commit when necessary
-from bzrlib.branch import Branch
+"""Runs etckeeper pre-commit when necessary."""
+
+from bzrlib.mutabletree import MutableTree
from bzrlib.errors import BzrError, NotLocalUrl
import os
import subprocess
-def etckeeper_precommit_hook(local, master, old_revno, old_revid,
- new_revno, new_revid, tree_delta, future_tree):
- if local is None:
- branch = master
- else:
- branch = local
- try:
- base = branch.bzrdir.root_transport.local_abspath(".")
- except NotLocalUrl:
- # No point in running etckeeper when committing to a remote branch
- return
- if not os.path.exists(os.path.join(base, ".etckeeper")):
+def etckeeper_startcommit_hook(tree):
+ if not os.path.exists(tree.abspath(".etckeeper")):
# Only run the commit hook when this is an etckeeper branch
return
- ret = subprocess.call(["etckeeper", "pre-commit", base])
+ ret = subprocess.call(["etckeeper", "pre-commit", tree.abspath(".")])
if ret != 0:
raise BzrError("etckeeper pre-commit failed")
-Branch.hooks.install_hook('pre_commit', etckeeper_precommit_hook)
-Branch.hooks.name_hook(etckeeper_precommit_hook, "etckeeper")
+MutableTree.hooks.install_hook('start_commit', etckeeper_startcommit_hook)
+MutableTree.hooks.name_hook(etckeeper_startcommit_hook, "etckeeper")
+
+if __name__ == "__main__":
+ from distutils.core import setup
+ setup(name="bzr-etckeeper",
+ package_dir={"bzrlib.plugins.etckeeper":__file__},
+ py_modules=["bzrlib.plugins.etckeeper"])