Running gofmt as a bzr hook

John Lenton john.lenton at canonical.com
Mon May 18 10:10:51 UTC 2015


In Push we have the following:

http://bazaar.launchpad.net/~ubuntu-push-hackers/ubuntu-push/trunk/view/head:/.precommit

maybe we want something similar in snappy?

On 15 May 2015 at 20:55, Alejandro J. Cura <alejandro.cura at canonical.com> wrote:
> That's very useful, thanks for sharing!
>
> On Fri, May 15, 2015 at 4:37 PM, Michael Terry
> <michael.terry at canonical.com> wrote:
>> 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
>>
>> --
>> snappy-devel mailing list
>> snappy-devel at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/snappy-devel
>>
>
> --
> snappy-devel mailing list
> snappy-devel at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/snappy-devel



More information about the snappy-devel mailing list