<div dir="ltr">I use an unenlightened editor that doesn't run gofmt upon saving a file.<div><br></div><div>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</div><div><br></div><div>"""</div><div><div>from bzrlib import hooks</div><div><br></div><div>def run_gofmt(local, master, old_revno, old_revid, future_revno, future_revid, tree_delta, future_tree):</div><div>    import os, subprocess</div><div>    from bzrlib import errors, workingtree</div><div>    basedir = workingtree.WorkingTree.open(master.user_url).basedir</div><div>    if os.path.exists(basedir + "/cmd/snappy/main.go") and subprocess.check_output(["gofmt", "-l", basedir]):</div><div>        raise errors.BzrError("Run gofmt, you have style errors.")</div><div><br></div><div>hooks.install_lazy_named_hook('bzrlib.branch', 'Branch.hooks',</div><div>    'pre_commit', run_gofmt, 'Run gofmt on snappy branches')</div><div>"""</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">-mt</div></div>
</div></div>