Skip to content

Using the GIT Hooks

Nick Kwiatkowski edited this page Nov 25, 2026 · 1 revision

Using the GIT Hooks

clif hook installs a git pre-commit hook that runs CFLint over what is being committed, through clif lint --staged --strict: the staged content, not the working tree, with every CFLint severity level failing the commit.

clif hook install [--dir <dir>] [--changed-lines] [--log <file>] [--force]
clif hook uninstall [--dir <dir>]
clif hook check
clif hook run pre-commit [--changed-lines] [--log <file>]
clif hook run post-commit [--log <file>]

Subcommands

Subcommand What it does
install Writes pre-commit (and, with --log, post-commit) into <dir> (default .githooks at the repository root) and points this clone's core.hooksPath at it
uninstall Removes the hooks install wrote, and core.hooksPath if it points at them
check Exits 1 when the repository has a .cflintrc and its pre-commit hook does not run clif, so an un-hooked clone is caught by CI or a setup script
run pre-commit / run post-commit What the installed hooks call; not normally run by hand

Options

Option Applies to Description
--dir <dir> install, uninstall Hook directory (default .githooks)
--changed-lines install, run pre-commit Fail only on findings in lines the commit adds or alters; a finding elsewhere in a touched file was there before
--log <file> install, run Append one line per commit attempt (see Commit log)
--force install Overwrite a hook in <dir> that clif did not write (otherwise it is left alone)

Setting up a repository

clif hook install          # lint what is committed; every CFLint level fails
git add .githooks
git commit -m "Add clif pre-commit hook"

Commit .githooks/ so the hook lives in the repository. Git does not copy core.hooksPath to new clones, so each clone runs clif hook install once. Add clif hook check to CI or a setup script to catch a clone that hasn't:

clif hook check || { echo "Run: clif hook install"; exit 1; }

Variations:

clif hook install --changed-lines                  # only new/changed lines must be clean
clif hook install --log ~/logs/cflint-commits.log  # also log every attempt
clif hook install --dir tools/hooks --force        # a different directory, replacing an existing hook

What a commit looks like

A clean commit passes silently. A commit with findings is blocked:

$ git commit -m "ABC-123 Add order totals"
src/orders.cfc:41:9: [warning MISSING_VAR] Variable total is not declared with a var statement.
$ echo $?
1

Fix the finding (or add a deliberate @CFLintIgnore), stage it, and commit again.

Situation Behaviour
clif not installed on the machine The hook stops the commit and says so
Skipping once SKIP=lint git commit … (also SKIP=clif, or PREK_SKIP=lint). Logged as SKIP when --log is set
Another tool's hook already in .githooks/ Left alone unless --force

Commit log

With --log <file>, each attempt appends one line:

TIMESTAMP | TICKET | HASH | PASS/FAIL | REPO | MESSAGE
Field Value
TIMESTAMP When the commit was attempted
TICKET The first ABC-123-style key in the commit subject, else the branch name
HASH The commit hash, filled in by the post-commit hook; a blocked commit keeps --------
PASS/FAIL The result (SKIP when skipped)
REPO The repository
MESSAGE The commit message (filled in by post-commit; -------- when blocked)

CLIF_COMMIT_LOG (or CFLINT_COMMIT_LOG) overrides the path.

Exit status

Code Meaning
0 Passed, skipped, or done
1 The commit has findings (run pre-commit), or the hook is missing (check)
2 Not a git repository, a hook in the way, or a usage error

Using pre-commit or prek instead

clif ships a hook definition for pre-commit and prek. List it in your committed .pre-commit-config.yaml:

repos:
  - repo: https://github.com/cfmleditor/clif
    rev: v0.7.7
    hooks:
      - id: clif-cflint
Hook property Value
id clif-cflint
entry clif cflint --strict -q
files \.(cfm|cfc)$ (staged .cfm and .cfc files)
language system (clif must be installed and on PATH)

pre-commit stashes unstaged changes before running, so the files passed are as staged.

Ratchets in the hook

To adopt rules on existing code, combine the hook with a baseline in CI (see Linting projects and code), or install with --changed-lines so only the lines a commit touches must be clean.

← Running the CLIF command-line tool · Home

Clone this wiki locally