diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 3e4dc9e..6c1c733 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -161,6 +161,12 @@ entry: name-tests-test language: python files: (^|/)tests/.+\.py$ +- id: no-commit-keywords + name: "Don't commit when nocommit keyword is present" + entry: no-commit-keywords + language: script + always_run: true + types: [text] - id: no-commit-to-branch name: "Don't commit to branch" entry: no-commit-to-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e45511..b6fee0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +3.2.0 - 2020-06-10 +================== + +### Features +- `no-commit-keywords`: block commits when 'nocommit' or other keywords are present + 3.1.0 - 2020-05-20 ================== diff --git a/README.md b/README.md index 6c7fba9..788c9ee 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ Replaces or checks mixed line ending. Assert that files in tests/ end in `_test.py`. - Use `args: ['--django']` to match `test*.py` instead. +#### `no-commit-keywords` +Protect branches from checkins when 'nocommit' keyword is present. Used to remind the author to prevent work-in-progress state from being committed. + #### `no-commit-to-branch` Protect specific branches from direct checkins. - Use `args: [--branch, staging, --branch, master]` to set the branch. diff --git a/pre_commit_hooks/no_commit_keywords.sh b/pre_commit_hooks/no_commit_keywords.sh new file mode 100644 index 0000000..c9dd19e --- /dev/null +++ b/pre_commit_hooks/no_commit_keywords.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +NOCOMMIT_PRESENT=$(git grep --ignore-case nocommit) + +if [ -n $NOCOMMIT_PRESENT ] +then + echo "#nocommit tagged - commit prevented" + echo $NOCOMMIT_PRESENT + exit 1 +else + exit 0 +fi + + diff --git a/setup.cfg b/setup.cfg index 0f7721f..5ee977b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pre_commit_hooks -version = 3.1.0 +version = 3.2.0 description = Some out-of-the-box hooks for pre-commit. long_description = file: README.md long_description_content_type = text/markdown @@ -52,6 +52,7 @@ console_scripts = forbid-new-submodules = pre_commit_hooks.forbid_new_submodules:main mixed-line-ending = pre_commit_hooks.mixed_line_ending:main name-tests-test = pre_commit_hooks.tests_should_end_in_test:main + no-commit-keywords = pre_commit_hooks.no_commit_keywords:main no-commit-to-branch = pre_commit_hooks.no_commit_to_branch:main pre-commit-hooks-removed = pre_commit_hooks.removed:main pretty-format-json = pre_commit_hooks.pretty_format_json:main