Running gofmt as a bzr hook
Michael Terry
michael.terry at canonical.com
Fri May 15 19:37:50 UTC 2015
I use an unenlightened editor that doesn't run gofmt upon saving a file.
So to avoid rookie mistakes, I wrote this tiny bzr hook to run gofmt during
a bzr commit (only for snappy branches). If you like it too, save it as
~/.bazaar/plugins/gofmt.py
"""
from bzrlib import hooks
def run_gofmt(local, master, old_revno, old_revid, future_revno,
future_revid, tree_delta, future_tree):
import os, subprocess
from bzrlib import errors, workingtree
basedir = workingtree.WorkingTree.open(master.user_url).basedir
if os.path.exists(basedir + "/cmd/snappy/main.go") and
subprocess.check_output(["gofmt", "-l", basedir]):
raise errors.BzrError("Run gofmt, you have style errors.")
hooks.install_lazy_named_hook('bzrlib.branch', 'Branch.hooks',
'pre_commit', run_gofmt, 'Run gofmt on snappy branches')
"""
--
-mt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/snappy-devel/attachments/20150515/3b599729/attachment.html>
More information about the snappy-devel
mailing list