我正在使用Android Studio(itellij)IDE和Git作爲VCS的內置支持。可以配置Android Studio在提交Git提交之前運行gradle任務嗎?
是否有任何鉤子/選項來謂詞提交成功運行一些gradle任務時的提交。正如你可能會懷疑的那樣,我試圖自動運行整個單元測試套件,並在本地單元測試失敗時阻止本地提交。
我正在使用Android Studio(itellij)IDE和Git作爲VCS的內置支持。可以配置Android Studio在提交Git提交之前運行gradle任務嗎?
是否有任何鉤子/選項來謂詞提交成功運行一些gradle任務時的提交。正如你可能會懷疑的那樣,我試圖自動運行整個單元測試套件,並在本地單元測試失敗時阻止本地提交。
仍然需要調查的git提交如何掛鉤甚至工作
在
.git
文件夾中創建一個hooks
目錄,將文件名 「pre-commit
」
(也可以執行,如果你不在Windo上WS)
但正如sschuberth在your linked question提到:
在
pre-commit
鉤添加長時間運行的任務通常是一個壞主意,因爲它會阻止你的工作。
此種檢查應該門合併該打破測試
換句話說提交的CI系統上進行,提交和推到中間回購與預先接收鉤,這將拒絕你的推如果整個單元測試套件在任何時候都會失敗。
的OP Creos指出in the comments的following pre-commit hook gist example通過Chad Maughan,是一個很好的模板:
#!/bin/sh
# this hook is in SCM so that it can be shared
# to install it, create a symbolic link in the projects .git/hooks folder
#
# i.e. - from the .git/hooks directory, run
# $ ln -s ../../git-hooks/pre-commit.sh pre-commit
#
# to skip the tests, run with the --no-verify argument
# i.e. - $ 'git commit --no-verify'
# stash any unstaged changes
git stash -q --keep-index
# run the tests with the gradle wrapper
./gradlew test
# store the last exit code in a variable
RESULT=$?
# unstash the unstashed changes
git stash pop -q
# return the './gradlew test' exit code
exit $RESULT
你試過一個pre-commit鉤子? – intboolstring
謝謝,我其實只是發現這個http://stackoverflow.com/questions/10234192/how-to-write-a-git-pre-commit-hook-that-prevents-committing-of-an-android-projec但仍然需要調查如何git提交掛鉤甚至工作 – Creos