diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee0b0e8..4200d2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,3 +8,23 @@ repos: args: [ --fix ] # Run the formatter. - id: ruff-format +- repo: local + hooks: + - id: commitizen-branch + name: commitizen conditionally check branch + description: > + Commitizen fails when there are no new commits. To overcome this, we created + tiny wrapper that verifies there are commits to check. + + Original description from Commitizen: + Check all commit messages that are already on the current branch but not the + default branch on the origin repository. Useful for checking messages after + the fact (e.g., pre-push or in CI) without an expensive check of the entire + repository history. + entry: ./conditional-commitizen.sh + always_run: true + language: python + minimum_pre_commit_version: "1.4.3" + additional_dependencies: [ + 'commitizen', + ] diff --git a/conditional-commitizen.sh b/conditional-commitizen.sh new file mode 100755 index 0000000..a3b8137 --- /dev/null +++ b/conditional-commitizen.sh @@ -0,0 +1,3 @@ +#!/bin/sh +log=$(git log origin/HEAD..HEAD | wc -l) +if [ "$log" -gt 0 ]; then cz check --rev-range origin/HEAD..HEAD; fi