Link Search Menu Expand Document

Hook Chaining

Did you have git repositories with other pre-commit/pre-push hooks? Are you worried that installing Talisman will clobber the existing git hooks?
Worry not! Installation of Talisman does no such thing.

If the installation script finds any existing hooks, it will only indicate so on the console. You will have to take the extra step to employ git hook chaining to allow Talisman to also take effect
To achieve running multiple hooks we suggest (but not limited to) the following two tools:

  1. With Pre-commit tool (for Linux/Unix)
  2. With Husky tool (for Linux/Unix/Windows)

With Pre-commit tool (for Linux/Unix)

Use pre-commit tool to manage all the existing hooks along with Talisman. In the suggestion, it will prompt the following code to be included in .pre-commit-config.yaml

    -   repo: local
        hooks:
        -   id: talisman-precommit
            name: talisman
            entry: bash -c 'if [ -n "${TALISMAN_HOME:-}" ]; then ${TALISMAN_HOME}/talisman_hook_script pre-commit; else echo "TALISMAN does not exist. Consider installing from https://github.com/thoughtworks/talisman . If you already have talisman installed, please ensure TALISMAN_HOME variable is set to where talisman_hook_script resides, for example, TALISMAN_HOME=${HOME}/.talisman/bin"; fi'
            language: system
            pass_filenames: false
            types: [text]
            verbose: true

With Husky tool (for Linux/Unix/Windows)

husky is an npm module for managing git hooks. In order to use husky, make sure you have set TALISMAN_HOME to $PATH.

Existing Users

If you already are using husky, add the following lines to husky pre-commit in package.json

Windows

    "bash -c '\"%TALISMAN_HOME%\\${TALISMAN_BINARY_NAME}\" --githook pre-commit'"

Linux/Unix

    $TALISMAN_HOME/talisman_hook_script pre-commit

New Users

If you want to use husky with multiple hooks along with talisman, add the following snippet to you package json.

Windows

     {
        "husky": {
          "hooks": {
            "pre-commit": "bash -c '\"%TALISMAN_HOME%\\${TALISMAN_BINARY_NAME}\" --githook pre-commit'" && "other-scripts"
            }
        }
    }

Linux/Unix

    {
      "husky": {
       "hooks": {
         "pre-commit": "$TALISMAN_HOME/talisman_hook_script pre-commit" && "other-scripts"
          }
        }
      }

© 2015-2020 ThoughtWorks, Inc.