我需要在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預提交鉤子