Pre-commit: support hooks located in repository

Created on 3 May 2016  路  5Comments  路  Source: pre-commit/pre-commit

- repo: ./pre-commit-hooks
  sha: ''
  hooks:
  - id: vault
Updating pre-commit-hooks...An unexpected error has occurred: CalledProcessError: Command: ('/usr/local/bin/git', 'clone', '--no-checkout', 'pre-commit-hooks', '/Users/gretel/.pre-commit/repoiXzY0j')
Return code: 128
Expected return code: 0
Output: (none)
Errors:
    fatal: repository 'pre-commit-hooks' does not exist

All 5 comments

You'll need to use full paths: http://pre-commit.com/#developing-hooks-interactively

this is why i was requesting to support ./ style paths. it's kinda counterfeiting the concept of using git when pre-commit requires to have static paths in it's configuration, i'd say.

I think what you actually want to use is the (still undocumented unfortunately) local hooks:
https://github.com/pre-commit/pre-commit/pull/226

This lets you use the current repository to configure hooks.

The reason we can't really support relative paths is they need to refer to a universally accessible location (since hooks are cached). If we allowed relative paths, depending on cwd this could refer to a different location (and different hooks!). Local hooks aren't cached since they don't create an environment

working fine now with repo-local script. may i suggest this example to have it less-undocumented:

-   repo: local
    hooks:
    -   id: vault
        name: Ansible Vault Check
        language: script
        description: Pre-commit hook that verifies if all files containing 'vault'
            in the name are encrypted.
        files: .*vault.*\.(yml|yaml)$
        entry: pre-commit-hooks/vault.sh

local hooks are now documented here: http://pre-commit.com/#repository-local-hooks

Was this page helpful?
0 / 5 - 0 ratings