我正在使用 Android Studio (itellij) IDE 和对 Git 作为 VCS 的内置支持。
是否有任何 Hook /选项可以预测在成功运行某个 gradle 任务时提交提交。您可能会怀疑,我正在尝试自动运行整个单元测试套件,并在任何单元测试失败时阻止本地提交。
最佳答案
still need to investigate how git commit hooks even work
create a
hooks
directory in your.git
folder and just name the file "pre-commit
"
(如果你不是在 Windows 上,也让它可执行)
但如your linked question中所述通过 sschuberth :
Adding long-running tasks in a
pre-commit
hook generally is a bad idea as it blocks you from working.
Such checks should be done on a CI system that gates merges of commits that break tests
换句话说,提交并推送到带有预接收 Hook 的中间存储库,如果整个单元测试套件在任何时候失败,它将拒绝您的推送。
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
关于git - 可以将 Android Studio 配置为在提交 Git 提交之前运行 gradle 任务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38416126/