Giter Club home page Giter Club logo

captain-hook's Introduction

Captain Hook

build Maintainability Maven Central

Gradle plugin for installing Git hooks.

Usage

In the root project's build.gradle, apply the plugin:

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath 'com.github.tjni.captainhook:captain-hook:0.1.4'
  }
}

apply plugin: 'com.github.tjni.captainhook'

Later in your script, to add a pre-commit hook, write:

captainHook {
  preCommit = 'echo "Hello, World!"'
}

By default, the plugin will add, update, or remove hooks whenever any Gradle task is run. This behavior can be disabled by specifying autoApplyGitHooks = false in the same block.

Hooks

The hooks that are available are:

  • applypatchMsg
  • preApplypatch
  • postApplypatch
  • preCommit
  • preMergeCommit
  • prepareCommitMsg
  • commitMsg
  • postCommit
  • preRebase
  • postCheckout
  • postMerge
  • prePush
  • preReceive
  • update
  • postReceive
  • postUpdate
  • pushToCheckout
  • preAutoGc
  • postRewrite
  • sendemailValidate

Staging

Captain Hook also can help you apply automatic code changes to files in the staging area prior to your commit. This is a great way to improve code quality unobtrusively.

captainHook {
  preCommit = './gradlew staging spotlessApply'
}

The staging modifier is a signal to Captain Hook to snapshot the state of your working directory before running subsequent tasks. If an error happens, it will do its best to restore your state. If no error occurs, but some staged files were modified, it will add them to your in-progress commit.

Captain Hook will leave untracked files alone, including changes that are made by the pre-commit hook. For example, the spotlessApply task from the Spotless plugin will run on every file and can lead to modifications to the untracked files.

To address this, the plugin will create a Gradle project property on the root project called staging, with type List<Path>, that contains the absolute paths to each file in the staging area. It's possible to create wrapper tasks that configure the underlying tasks to pay attention only to these files.

Attribution

This would not exist if not for the great projects that came before this. The behavior of this plugin is transcribed from husky and lint-staged, except with fewer features and adapted to Java & Gradle.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.