2

我正在使用Android Studio(itellij)IDE和Git作爲VCS的內置支持。可以配置Android Studio在提交Git提交之前運行gradle任務嗎?

是否有任何鉤子/選項來謂詞提交成功運行一些gradle任務時的提交。正如你可能會懷疑的那樣,我試圖自動運行整個單元測試套件,並在本地單元測試失敗時阻止本地提交。

+0

你試過一個pre-commit鉤子? – intboolstring

+0

謝謝,我其實只是發現這個http://stackoverflow.com/questions/10234192/how-to-write-a-git-pre-commit-hook-that-prevents-committing-of-an-android-projec但仍然需要調查如何git提交掛鉤甚至工作 – Creos

回答

2

仍然需要調查的git提交如何掛鉤甚至工作

由於shown in this gist

.git文件夾中創建一個hooks目錄,將文件名 「pre-commit

(也可以執行,如果你不在Windo上WS)

但正如sschuberthyour linked question提到:

pre-commit鉤添加長時間運行的任務通常是一個壞主意,因爲它會阻止你的工作。
此種檢查應該門合併該打破測試

換句話說提交的CI系統上進行,提交和推到中間回購與預先接收鉤,這將拒絕你的推如果整個單元測試套件在任何時候都會失敗。


OP Creos指出in the commentsfollowing 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 
+0

謝謝,請將此鏈接添加到您的答案,因爲它是一個偉大的模板https://gist.github.com/chadmaughan/5889802 – Creos

+0

@Creos當然,我已經包括預先提交鉤。 – VonC

+0

回答你的問題:是的,在本地做它會阻止你,它很爛,但我不知道我的項目是否需要在現階段爲CI付錢......我需要查看git hub,看看是否有任何低點 - 小型項目的成本或免費選項。我剛剛瞭解了鉤子,但我懷疑預先接收不會在github上免費工作,因爲有人需要爲他們的服務器上的CPU週期支付... – Creos