Go:git gofmt pre-commit hook
来源:互联网 发布:cad仿真软件 编辑:程序博客网 时间:2024/06/06 00:42
我们使用 git 做 Go 源码的版本控制,在提交前,我们需要对代码自动格式,并且当未格式的时候,输出一些信息,下面是一个这样的脚本:
注:该脚本来源于:http://golang.org/misc/git/pre-commit
关于介绍清理 Go 代码的小文章:An Introduction to Go Tools and Clean Code
#!/bin/sh # Copyright 2012 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. # git gofmt pre-commit hook # # To use, store as .git/hooks/pre-commit inside your repository and make sure # it has execute permissions. # # This script does not handle file names that contain spaces. gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') [ -z "$gofiles" ] && exit 0 unformatted=$(gofmt -l $gofiles) [ -z "$unformatted" ] && exit 0 # Some files are not gofmt'd. Print message and fail. echo >&2 "Go files must be formatted with gofmt. Please run:" for fn in $unformatted; do echo >&2 " gofmt -w $PWD/$fn" done exit 1
0 0
- Go:git gofmt pre-commit hook
- SVN pre-commit hook
- SVN configurable pre-commit hook
- git pre-commit 默认设置
- 【指导】iOS代码静态检查 -- clang format (+ git pre-commit hook + jenkins)
- 基于python开发pre-commit hook达到对git提交时间的控制
- eclipse svn commit 报错 Commit blocked by pre-commit hook
- SVN提交报错"Commit blocked by pre-commit hook"的解决办法
- 发布svn一直报错Commit blocked by pre-commit hook (exit code 1) with output
- svn提交问题--Commit blocked by pre-commit hook(exit code 1)with output:
- git hook之prepare-commit-msg
- use pep8 check code by pre-commit git hooks
- git之pre-commit 同步提交代码实现
- go标准命令详解0.9 go fmt与gofmt
- svn: Commit blocked by pre-commit hook (exit code 1) with output: Log format error 提交Log格式错误
- svn: Commit blocked by pre-commit hook (exit code 1) with output: Log format error 提交Log格式错误
- svn: Commit blocked by pre-commit hook (exit code 255) with output:报错分析及解决方法
- 利用git hook每次commit时执行一些其它操作。
- golang实现快速排序
- golang的类型转换的坑和分析
- Google Chrome 中的高性能网络
- [体会]用异或交换数值
- go(golang)之slice的小想法1
- Go:git gofmt pre-commit hook
- Gradle Plugin for Android Development User Guide (2)
- grunt-contrib-connect使用心得
- gulp plugin开发
- Gulp思维——Gulp高级技巧
- 关于嵌入式, 知乎上的一些回答
- Hello, world!_0
- Hibernate-core 4.3.6 Final 配置中出现的一些小问题
- How to fix 远程计算机需要网络级别身份验证 when using mstsc on XP