我需要在Java中编写Git预提交钩子,它会在实际提交之前检查开发人员提交的代码是否根据特定的eclipse代码格式化程序进行格式化,否则拒绝提交。是否有可能在Java中编写预提交钩子?在Git中编写GIT预提交钩子?
5
A
回答
5
这个想法是调用一个脚本,依次调用你的java程序(检查格式)。
你可以see here an example written in python,它调用java。
try:
# call checkstyle and print output
print call(['java', '-jar', checkstyle, '-c', checkstyle_config, '-r', tempdir])
except subprocess.CalledProcessError, ex:
print ex.output # print checkstyle messages
exit(1)
finally:
# remove temporary directory
shutil.rmtree(tempdir)
这other example calls directly ant
,为了执行ant脚本(这又调用Java JUnit测试套件)
#!/bin/sh
# Run the test suite.
# It will exit with 0 if it everything compiled and tested fine.
ant test
if [ $? -eq 0 ]; then
exit 0
else
echo "Building your project or running the tests failed."
echo "Aborting the commit. Run with --no-verify to ignore."
exit 1
fi
1
你可以写钩,可以通过外壳可以理解的任何语言,用正确配置的解释器(bash中,蟒蛇,perl的)等
但是,为什么不写Java代码格式在Java中,并从预提交钩子调用它。
相关问题
- 1. Git远程/共享预提交钩子
- 2. Git预提交钩子在提交后添加文件
- 3. 在预提交钩子中提高git警告
- 4. 从Git钩子中排除提交?
- 5. 如何在Git中编写预合并钩子?
- 6. 检查预提交钩子shell脚本中的git状态
- 7. 当var_dump存在时,终止git预提交钩子
- 8. 在git中提交一个提交钩子
- 9. 如何编写一个Git预提交钩子,防止在测试项目失败时提交Android项目?
- 10. Git子模块提交挂钩
- 11. Git提交钩子 - 全局设置
- 12. 提交后使用git钩子
- 13. 每个分支的Git提交钩子
- 14. 使用PHP编写git钩子
- 15. Git预先提交钩子检查消息
- 16. 了解git commit - 只有和预先提交的钩子
- 17. Git预提交钩子 - 没有这样的文件或目录
- 18. 从STDIN读取Git预提交钩子(使用PHP)
- 19. 继续部分git svn dcommit失败预先提交钩子
- 20. Hudson构建失败时Git的预先提交钩子
- 21. git gitolite(v3)为所有提交消息预接收钩子
- 22. 编写一个git钩子来在本地提交时自动修改代码
- 23. 预提交钩子在提交文件
- 24. 如何使用git钩子预先提交来停止提交主人
- 25. git中的预取钩子功能
- 26. GIT预接挂钩
- 27. 预推git挂钩?
- 28. 用于在git中添加注释标签的预提交钩子的分类
- 29. 的grep在预提交git的正则表达式钩
- 30. SVN预提交钩子