git - 可以将 Android Studio 配置为在提交 Git 提交之前运行 gradle 任务吗?

标签 git android-studio intellij-idea android-gradle-plugin gradle-plugin

我正在使用 Android Studio (itellij) IDE 和对 Git 作为 VCS 的内置支持。

是否有任何 Hook /选项可以预测在成功运行某个 gradle 任务时提交提交。您可能会怀疑,我正在尝试自动运行整个单元测试套件,并在任何单元测试失败时阻止本地提交。

最佳答案

still need to investigate how git commit hooks even work

作为shown in this gist

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/

相关文章:

Android Studio 和 PhoneGap,模块 android 不受 gradle 支持

java - 进程意外退出:构建失败,出现异常

java - 为什么Gradle编译.java文件而不创建我的.jar?

GIT:按作者组过滤日志

windows - 混帐庆典 : how to change where the MinTTY configuration file is stored?

git - 如果它迫使你留在本地,为什么要使用 rebase?

android - android studio中的模拟器从侧边栏开始

java - IntelliJ : create gradle modules in subfolders

java - IntelliJ - 连接到 PostgreSQL 时出现问题

git - 如何删除 Github 和 Bitbucket 上的 git 提交