Can Git hook scripts be managed along with the repository?

前端 未结 11 1167
独厮守ぢ
独厮守ぢ 2020-11-22 14:00

We\'d like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 14:14

    For gradle users

    I found these scripts very useful for gradle projects.

    build.gradle

    apply from: rootProject.file('gradle/install-git-hooks.gradle')

    gradle/install-git-hooks.gradle

    tasks.create(name: 'gitExecutableHooks') {
        doLast {
            Runtime.getRuntime().exec("chmod -R +x .git/hooks/");
        }
    }
    task installGitHooks(type: Copy) {
        from new File(rootProject.rootDir, 'pre-commit')
        into { new File(rootProject.rootDir, '.git/hooks') }
    }
    gitExecutableHooks.dependsOn installGitHooks
    clean.dependsOn gitExecutableHooks
    

    pre-commit

    .... your pre commit scripts goes here
    

提交回复
热议问题