From f3b6c222fb11c96e2f8bbaa0622f46c8ec486874 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 19 Nov 2022 15:52:50 +0100 Subject: Merging upstream version 0.18.0. Signed-off-by: Daniel Baumann --- .devcontainer/Dockerfile | 21 + .devcontainer/devcontainer.json | 56 +++ .devcontainer/postCreateCommand.sh | 23 ++ .flake8 | 11 - .github/workflows/checks.yml | 44 +- .pre-commit-hooks.yaml | 23 +- CHANGELOG.md | 40 +- Dockerfile | 2 +- README.md | 2 +- Vagrantfile | 49 --- doc-requirements.txt | 2 +- docs/configuration.md | 234 ++++++++--- docs/contrib_rules.md | 20 +- docs/contributing.md | 126 ++++-- docs/demos/asciicinema.json | 14 +- docs/extra.css | 8 + docs/images/dev-container.png | Bin 0 -> 212226 bytes docs/images/gitlint-packages.drawio.svg | 351 ++++++++++++++++ docs/images/gitlint-packages.png | Bin 0 -> 51975 bytes docs/index.md | 118 ++++-- docs/rules.md | 287 +++++++------ docs/user_defined_rules.md | 76 ++-- examples/my_commit_rules.py | 16 +- examples/my_configuration_rules.py | 7 +- examples/my_line_rules.py | 17 +- gitlint-core/gitlint/__init__.py | 2 +- gitlint-core/gitlint/cache.py | 33 +- gitlint-core/gitlint/cli.py | 135 ++++-- gitlint-core/gitlint/config.py | 260 ++++++------ .../gitlint/contrib/rules/authors_commit.py | 46 +++ .../gitlint/contrib/rules/conventional_commit.py | 4 +- .../contrib/rules/disallow_cleanup_commits.py | 22 + gitlint-core/gitlint/contrib/rules/signedoff_by.py | 3 +- gitlint-core/gitlint/deprecation.py | 40 ++ gitlint-core/gitlint/display.py | 6 +- gitlint-core/gitlint/exception.py | 4 +- gitlint-core/gitlint/files/gitlint | 10 +- gitlint-core/gitlint/git.py | 286 +++++++++---- gitlint-core/gitlint/hooks.py | 18 +- gitlint-core/gitlint/lint.py | 57 ++- gitlint-core/gitlint/options.py | 34 +- gitlint-core/gitlint/rule_finder.py | 71 ++-- gitlint-core/gitlint/rules.py | 181 +++++--- gitlint-core/gitlint/shell.py | 30 +- gitlint-core/gitlint/tests/base.py | 81 ++-- gitlint-core/gitlint/tests/cli/test_cli.py | 444 ++++++++++++-------- gitlint-core/gitlint/tests/cli/test_cli_hooks.py | 157 +++---- gitlint-core/gitlint/tests/config/test_config.py | 109 +++-- .../gitlint/tests/config/test_config_builder.py | 88 ++-- .../gitlint/tests/config/test_config_precedence.py | 46 ++- .../gitlint/tests/config/test_rule_collection.py | 9 +- .../tests/contrib/rules/test_authors_commit.py | 106 +++++ .../contrib/rules/test_conventional_commit.py | 39 +- .../contrib/rules/test_disallow_cleanup_commits.py | 35 ++ .../tests/contrib/rules/test_signedoff_by.py | 5 +- .../gitlint/tests/contrib/test_contrib_rules.py | 34 +- .../tests/expected/cli/test_cli/test_debug_1 | 25 +- .../cli/test_cli/test_input_stream_debug_2 | 7 +- .../cli/test_cli/test_lint_staged_msg_filename_2 | 11 +- .../expected/cli/test_cli/test_lint_staged_stdin_2 | 11 +- .../tests/expected/cli/test_cli/test_named_rules_2 | 7 +- gitlint-core/gitlint/tests/git/test_git.py | 65 +-- gitlint-core/gitlint/tests/git/test_git_commit.py | 460 +++++++++++++++------ gitlint-core/gitlint/tests/git/test_git_context.py | 41 +- .../gitlint/tests/rules/test_body_rules.py | 27 +- .../tests/rules/test_configuration_rules.py | 66 +-- .../gitlint/tests/rules/test_meta_rules.py | 48 ++- gitlint-core/gitlint/tests/rules/test_rules.py | 2 - .../gitlint/tests/rules/test_title_rules.py | 56 ++- .../gitlint/tests/rules/test_user_rules.py | 69 ++-- .../tests/samples/commit_message/fixup_amend | 1 + gitlint-core/gitlint/tests/samples/config/AUTHORS | 2 + .../user_rules/import_exception/invalid_python.py | 1 - .../user_rules/incorrect_linerule/my_line_rule.py | 2 - .../tests/samples/user_rules/my_commit_rules.py | 7 +- .../samples/user_rules/parent_package/__init__.py | 1 - .../user_rules/parent_package/my_commit_rules.py | 2 - gitlint-core/gitlint/tests/test_cache.py | 4 +- gitlint-core/gitlint/tests/test_deprecation.py | 23 ++ gitlint-core/gitlint/tests/test_display.py | 22 +- gitlint-core/gitlint/tests/test_hooks.py | 68 +-- gitlint-core/gitlint/tests/test_lint.py | 188 +++++---- gitlint-core/gitlint/tests/test_options.py | 15 +- gitlint-core/gitlint/tests/test_utils.py | 15 +- gitlint-core/gitlint/utils.py | 12 +- gitlint-core/setup.py | 50 +-- pyproject.toml | 5 + qa/base.py | 97 +++-- qa/expected/test_commits/test_csv_hash_list_1 | 11 + qa/expected/test_commits/test_ignore_commits_1 | 2 + .../test_commits/test_lint_staged_msg_filename_1 | 12 +- qa/expected/test_commits/test_lint_staged_stdin_1 | 12 +- qa/expected/test_config/test_config_from_env_1 | 12 +- qa/expected/test_config/test_config_from_env_2 | 11 +- .../test_config/test_config_from_file_debug_1 | 12 +- qa/expected/test_gitlint/test_commit_binary_file_1 | 94 +++++ .../test_user_defined_rules_examples_1 | 2 +- .../test_user_defined_rules_examples_2 | 2 +- .../test_user_defined_rules_examples_with_config_1 | 2 +- .../test_user_defined_rules_extra_1 | 4 +- qa/requirements.txt | 6 +- qa/samples/user_rules/extra/extra_rules.py | 24 +- qa/shell.py | 30 +- qa/test_commits.py | 161 ++++++-- qa/test_config.py | 80 ++-- qa/test_contrib.py | 20 +- qa/test_gitlint.py | 165 ++++++-- qa/test_hooks.py | 128 +++--- qa/test_named_rules.py | 8 +- qa/test_stdin.py | 35 +- qa/test_user_defined.py | 31 +- qa/utils.py | 8 +- requirements.txt | 2 +- run_tests.sh | 39 +- setup.py | 20 +- test-requirements.txt | 12 +- tools/create-test-repo.sh | 2 +- tools/windows/create-test-repo.bat | 2 +- 118 files changed, 4227 insertions(+), 2074 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/postCreateCommand.sh delete mode 100644 .flake8 delete mode 100644 Vagrantfile create mode 100644 docs/images/dev-container.png create mode 100644 docs/images/gitlint-packages.drawio.svg create mode 100644 docs/images/gitlint-packages.png create mode 100644 gitlint-core/gitlint/contrib/rules/authors_commit.py create mode 100644 gitlint-core/gitlint/contrib/rules/disallow_cleanup_commits.py create mode 100644 gitlint-core/gitlint/deprecation.py create mode 100644 gitlint-core/gitlint/tests/contrib/rules/test_authors_commit.py create mode 100644 gitlint-core/gitlint/tests/contrib/rules/test_disallow_cleanup_commits.py create mode 100644 gitlint-core/gitlint/tests/samples/commit_message/fixup_amend create mode 100644 gitlint-core/gitlint/tests/samples/config/AUTHORS create mode 100644 gitlint-core/gitlint/tests/test_deprecation.py create mode 100644 pyproject.toml create mode 100644 qa/expected/test_commits/test_csv_hash_list_1 create mode 100644 qa/expected/test_gitlint/test_commit_binary_file_1 diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b429c19 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,21 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3/.devcontainer/base.Dockerfile + +# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster +ARG VARIANT="3.10-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. +# COPY requirements.txt /tmp/pip-tmp/ +# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ +# && rm -rf /tmp/pip-tmp + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5889037 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,56 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3 +{ + "name": "Python 3", + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "VARIANT": "3.10", + // Options + "NODE_VERSION": "none" + } + }, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance" + ] + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "git": "latest", + "github-cli": "latest", + "sshd": "latest", + "homebrew": "latest" + }, + "postCreateCommand": "./.devcontainer/postCreateCommand.sh" +} \ No newline at end of file diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100755 index 0000000..4bbaf05 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,23 @@ +#!/bin/sh -x + +brew install asdf +source "$(brew --prefix asdf)/libexec/asdf.sh" + +# Install latest python +asdf plugin add python +asdf install python 3.11.0 +asdf global python 3.11.0 + +# You can easily install other python versions like so: +# asdf install python 3.6.15 +# asdf install python 3.7.15 +# asdf install python 3.8.15 +# asdf install python 3.9.15 +# asdf install python 3.10.8 +# asdf install python pypy3.9-7.3.9 + +# Setup virtualenv, install all dependencies +cd /workspaces/gitlint +$(asdf which python) -m venv .venv +source .venv/bin/activate +pip install -r requirements.txt -r test-requirements.txt -r doc-requirements.txt \ No newline at end of file diff --git a/.flake8 b/.flake8 deleted file mode 100644 index df7800e..0000000 --- a/.flake8 +++ /dev/null @@ -1,11 +0,0 @@ -[flake8] -# H307: like imports should be grouped together -# H405: multi line docstring summary not separated with an empty line -# H803: git title must end with a period -# H904: Wrap long lines in parentheses instead of a backslash -# H802: git commit title should be under 50 chars -# H701: empty localization string -extend-ignore = H307,H405,H803,H904,H802,H701 -# exclude settings files and virtualenvs -exclude = *settings.py,*.venv/*.py -max-line-length = 120 \ No newline at end of file diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 1ca2a9c..39b3782 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -7,21 +7,21 @@ jobs: runs-on: "ubuntu-latest" strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", pypy3] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.9] os: ["macos-latest", "ubuntu-latest"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.0.2 with: ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit # Because gitlint is a tool that uses git itself under the hood, we remove git tracking from the checked out - # code by temporarily renaming the .git directory. + # code by temporarily renaming the .git directory. # This is to ensure that the tests don't have a dependency on the version control of gitlint itself. - name: Temporarily remove git version control from code run: mv .git ._git - name: Setup python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4.2.0 with: python-version: ${{ matrix.python-version }} @@ -40,16 +40,28 @@ jobs: # COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} # run: coveralls + # Patch the commit-msg hook to make it work in GH CI + # Specifically, within the commit-msg hook, wrap the invocation of gitlint with `script` + + - name: Patch commit-msg hook + run: | + # Escape " to \" + sed -i -E '/^gitlint/ s/"/\\"/g' gitlint-core/gitlint/files/commit-msg + # Replace `gitlint ` with `script -e -q -c "gitlint "` + sed -i -E 's/^gitlint(.*)/script -e -q -c "\0"/' gitlint-core/gitlint/files/commit-msg + - name: Integration Tests run: ./run_tests.sh -i - - name: Integration Tests (GITLINT_USE_SH_LIB=0) + # Gitlint no longer uses `sh` by default, but for now we're still supporting the manual enablement of it. + # By setting GITLINT_USE_SH_LIB=1, we test whether this still works. + - name: Integration Tests (GITLINT_USE_SH_LIB=1) env: - GITLINT_USE_SH_LIB: 0 + GITLINT_USE_SH_LIB: 1 run: ./run_tests.sh -i - - name: PEP8 - run: ./run_tests.sh -p + - name: Code formatting (black) + run: ./run_tests.sh -f - name: PyLint run: ./run_tests.sh -l @@ -79,25 +91,25 @@ jobs: runs-on: windows-latest strategy: matrix: - python-version: [3.6] + python-version: ["3.10"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.0.2 with: ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit # Because gitlint is a tool that uses git itself under the hood, we remove git tracking from the checked out - # code by temporarily renaming the .git directory. + # code by temporarily renaming the .git directory. # This is to ensure that the tests don't have a dependency on the version control of gitlint itself. - name: Temporarily remove git version control from code run: Rename-Item .git ._git - + - name: Setup python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4.2.0 with: python-version: ${{ matrix.python-version }} - name: "Upgrade pip on Python 3" - if: matrix.python-version == '3.6' + if: matrix.python-version == '3.10' run: python -m pip install --upgrade pip - name: Install requirements @@ -126,8 +138,8 @@ jobs: run: pytest -rw -s qa continue-on-error: true # Known to fail at this point - - name: PEP8 - run: flake8 gitlint-core qa examples + - name: Code formatting (black) + run: black . - name: PyLint run: pylint gitlint-core\gitlint qa --rcfile=".pylintrc" -r n diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index f2ccc7f..24fd745 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,7 +1,16 @@ -- id: gitlint - name: gitlint - language: python - additional_dependencies: ["./gitlint-core[trusted-deps]"] - entry: gitlint - args: [--staged, --msg-filename] - stages: [commit-msg] +- id: gitlint + name: gitlint + description: Checks your git commit messages for style. + language: python + additional_dependencies: ["./gitlint-core[trusted-deps]"] + entry: gitlint + args: [--staged, --msg-filename] + stages: [commit-msg] +- id: gitlint-ci + name: gitlint + language: python + additional_dependencies: ["./gitlint-core[trusted-deps]"] + entry: gitlint + always_run: true + pass_filenames: false + stages: [manual] diff --git a/CHANGELOG.md b/CHANGELOG.md index 2546579..091b2a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # Changelog # + +## v0.18.0 (2022-11-16) ## +Contributors: +Special thanks to all contributors for this release - details inline! + +- Python 3.11 support +- Last release to support Python 3.6 ([EOL since 2021-12-23](https://endoflife.date/python)) +- **Behavior Change**: In a future release, gitlint will be switching to use `re.search` instead of `re.match` semantics for all rules. Your rule regexes might need updating as a result, gitlint will print a warning if so. [More details are in the docs](https://jorisroovers.com/gitlint/configuration/#regex-style-search). ([#254](https://github.com/jorisroovers/gitlint/issues/254)) +- gitlint no longer uses the [sh](https://amoffat.github.io/sh/) library by default in an attempt to reduce external dependencies. In case of issues, the use of `sh` can be re-enabled by setting the env var `GITLINT_USE_SH_LIB=1`. This fallback will be removed entirely in a future gitlint release. ([#351](https://github.com/jorisroovers/gitlint/issues/351)) +- `--commits` now also accepts a comma-separated list of commit hashes, making it possible to lint a list of non-contiguous commits without invoking gitlint multiple times ([#283](https://github.com/jorisroovers/gitlint/issues/283)) +- Improved handling of branches that have no commits ([#188](https://github.com/jorisroovers/gitlint/issues/189)) - thanks [domsekotill](https://github.com/domsekotill) +- Support for `GITLINT_CONFIG` env variable ([#189](https://github.com/jorisroovers/gitlint/issues/188)) - thanks [Notgnoshi](https://github.com/Notgnoshi) +- Added [a new `gitlint-ci` pre-commit hook](https://jorisroovers.com/gitlint/#gitlint-and-pre-commit-in-ci), making it easier to run gitlint through pre-commit in CI ([#191](https://github.com/jorisroovers/gitlint/issues/191)) - thanks [guillaumelambert](https://github.com/guillaumelambert) +- Contrib Rules: + - New [contrib-disallow-cleanup-commits](https://jorisroovers.com/gitlint/contrib_rules/#cc2-contrib-disallow-cleanup-commits) rule ([#312](https://github.com/jorisroovers/gitlint/issues/312)) - thanks [matthiasbeyer](https://github.com/matthiasbeyer) + - New [contrib-allowed-authors](https://jorisroovers.com/gitlint/contrib_rules/#cc3-contrib-allowed-authors) rule ([#358](https://github.com/jorisroovers/gitlint/issues/358)) - thanks [stauchert](https://github.com/stauchert) +- User Defined rules: + - Gitlint now recognizes `fixup=amend` commits (see related [git documentation](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)), available as `commit.is_fixup_amend_commit=True` + - Gitlint now parses diff **stat** information, available in `commit.changed_files_stats` ([#314](https://github.com/jorisroovers/gitlint/issues/314)) +- Bugfixes: + - Use correct encoding when using `--msg-filename` parameter ([#310](https://github.com/jorisroovers/gitlint/issues/310)) + - Various documentation fixes ([#244](https://github.com/jorisroovers/gitlint/issues/244)) ([#263](https://github.com/jorisroovers/gitlint/issues/263)) ([#266](https://github.com/jorisroovers/gitlint/issues/266)) ([#294](https://github.com/jorisroovers/gitlint/issues/294)) ([#295](https://github.com/jorisroovers/gitlint/issues/295)) ([#347](https://github.com/jorisroovers/gitlint/issues/347)) ([#364](https://github.com/jorisroovers/gitlint/issues/364)) - thanks [scop](https://github.com/scop), [OrBin](https://github.com/OrBin), [jtaylor100](https://github.com/jtaylor100), [stauchert](https://github.com/stauchert) +- Under-the-hood: + - Dependencies updated + - Moved to [black](https://github.com/psf/black) for formatting + - Fixed nasty CI issue ([#298](https://github.com/jorisroovers/gitlint/issues/298)) + - Unit tests fix ([#256](https://github.com/jorisroovers/gitlint/issues/256)) - thanks [carlsmedstad](https://github.com/carlsmedstad) + - Vagrant box removed in favor of github dev containers ([#348](https://github.com/jorisroovers/gitlint/issues/348)) + - Removed a few lingering references to the `master` branch in favor of `main` + - Moved [roadmap and project planning](https://github.com/users/jorisroovers/projects/1) to github projects + - Thanks to [sigmavirus24](https://github.com/sigmavirus24) for continued overall help and support + ## v0.17.0 (2021-11-28) ## Contributors: Special thanks to all contributors for this release, in particular [andersk](https://github.com/andersk) and [sigmavirus24](https://github.com/sigmavirus24). @@ -13,12 +45,12 @@ Special thanks to all contributors for this release, in particular [sigmavirus24 - Python 3.10 support - **New Rule**: [ignore-by-author-name](http://jorisroovers.github.io/gitlint/rules/#i4-ignore-by-author-name) allows users to skip linting commit messages made by specific authors -- `--commit ` flag to more easily lint a single commit message ([#141](https://github.com/jorisroovers/gitlint/issues/141)) +- `--commit ` flag to more easily lint a single commit message ([#141](https://github.com/jorisroovers/gitlint/issues/141)) - `--fail-without-commits` flag will force gitlint to fail ([exit code 253](https://jorisroovers.com/gitlint/#exit-codes)) when the target commit range is empty (typically when using `--commits`) ([#193](https://github.com/jorisroovers/gitlint/issues/193)) - Bugfixes: - [contrib-title-conventional-commits (CT1)](https://jorisroovers.com/gitlint/contrib_rules/#ct1-contrib-title-conventional-commits) now properly enforces the commit type ([#185](https://github.com/jorisroovers/gitlint/issues/185)) - [contrib-title-conventional-commits (CT1)](https://jorisroovers.com/gitlint/contrib_rules/#ct1-contrib-title-conventional-commits) now supports the BREAKING CHANGE symbol "!" ([#186](https://github.com/jorisroovers/gitlint/issues/186)) -- Heads-up: [Python 3.6 will become EOL at the end of 2021](https://endoflife.date/python). It's likely that future gitlint releases will stop supporting Python 3.6 as a result. We will continue to support Python 3.6 as long as its easily doable, which in practice usually means as long as our dependencies support it. +- Heads-up: [Python 3.6 will become EOL at the end of 2021](https://endoflife.date/python). It's likely that future gitlint releases will stop supporting Python 3.6 as a result. We will continue to support Python 3.6 as long as it's easily doable, which in practice usually means as long as our dependencies support it. - Under-the-hood: dependencies updated, test and github action improvements. ## v0.15.1 (2021-04-16) ## @@ -168,8 +200,8 @@ and [AlexMooney](https://github.com/AlexMooney) for their contributions. [Rules section of the documentation](http://jorisroovers.github.io/gitlint/rules/#m1-author-valid-email). - **Breaking change**: The `--commits` commandline flag now strictly follows the refspec format as interpreted by the [`git rev-list `](https://git-scm.com/docs/git-rev-list) command. This means - that linting a single commit using `gitlint --commits ` won't work anymore. Instead, for single commits, - users now need to specificy `gitlint --commits ^...`. On the upside, this change also means + that linting a single commit using `gitlint --commits ` won't work anymore. Instead, for single commits, + users now need to specificy `gitlint --commits ^...`. On the upside, this change also means that gitlint will now understand all refspec formatters, including `gitlint --commits HEAD` to lint all commits in the repository. This fixes [#23](https://github.com/jorisroovers/gitlint/issues/23). - **Breaking change**: Gitlint now always falls back on trying to read a git message from a local git repository, only diff --git a/Dockerfile b/Dockerfile index db3642e..8a4ad25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ # NOTE: --ulimit is required to work around a limitation in Docker # Details: https://github.com/jorisroovers/gitlint/issues/129 -FROM python:3.10-alpine +FROM python:3.11.0-alpine ARG GITLINT_VERSION RUN apk add git diff --git a/README.md b/README.md index e87dc37..ecf8298 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,4 @@ All contributions are welcome and very much appreciated! See [jorisroovers.github.io/gitlint/contributing](http://jorisroovers.github.io/gitlint/contributing) for details on how to get started - it's easy! -We maintain a [loose roadmap on our wiki](https://github.com/jorisroovers/gitlint/wiki/Roadmap). +We maintain a [loose project plan on Github Projects](https://github.com/users/jorisroovers/projects/1/views/1). diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index f913248..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,49 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -VAGRANTFILE_API_VERSION = "2" - -INSTALL_DEPS=<> /home/vagrant/.bashrc -grep 'source .venv36/bin/activate' /home/vagrant/.bashrc || echo 'source .venv36/bin/activate' >> /home/vagrant/.bashrc -EOF - -INSTALL_JENKINS=< /etc/apt/sources.list.d/jenkins.list' -sudo apt-get update -sudo apt-get install -y openjdk-8-jre -sudo apt-get install -y jenkins -EOF - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - - config.vm.box = "ubuntu/focal64" - - config.vm.define "dev" do |dev| - dev.vm.provision "gitlint", type: "shell", inline: "#{INSTALL_DEPS}" - # Use 'vagrant provision --provision-with jenkins' to only run jenkins install - dev.vm.provision "jenkins", type: "shell", inline: "#{INSTALL_JENKINS}" - end - - config.vm.network "forwarded_port", guest: 8080, host: 9080 - - if Vagrant.has_plugin?("vagrant-cachier") - config.cache.scope = :box - end - -end diff --git a/doc-requirements.txt b/doc-requirements.txt index 33ce51e..40febbe 100644 --- a/doc-requirements.txt +++ b/doc-requirements.txt @@ -1 +1 @@ -mkdocs==1.2.3 \ No newline at end of file +mkdocs==1.4.1 \ No newline at end of file diff --git a/docs/configuration.md b/docs/configuration.md index addf0c0..af49d7c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -11,7 +11,7 @@ gitlint generate-config You can also use a different config file like so: ```sh -gitlint --config myconfigfile.ini +gitlint --config myconfigfile.ini ``` The block below shows a sample `.gitlint` file. Details about rule config options can be found on the @@ -39,16 +39,17 @@ ignore=title-trailing-punctuation, T3 # precedence over this verbosity = 2 -# By default gitlint will ignore merge, revert, fixup and squash commits. +# By default gitlint will ignore merge, revert, fixup, fixup=amend, and squash commits. ignore-merge-commits=true ignore-revert-commits=true ignore-fixup-commits=true +ignore-fixup-amend-commits=true ignore-squash-commits=true -# Ignore any data send to gitlint via stdin +# Ignore any data sent to gitlint via stdin ignore-stdin=true -# Fetch additional meta-data from the local repository when manually passing a +# Fetch additional meta-data from the local repository when manually passing a # commit message to gitlint via stdin or --commit-msg. Disabled by default. staged=true @@ -58,6 +59,11 @@ staged=true # Disabled by default. fail-without-commits=true +# Whether to use Python `search` instead of `match` semantics in rules that use +# regexes. Context: https://github.com/jorisroovers/gitlint/issues/254 +# Disabled by default, but will be enabled by default in the future. +regex-style-search=true + # Enable debug mode (prints more output). Disabled by default. debug=true @@ -187,7 +193,7 @@ gitlint-ignore: all `gitlint-ignore: all` can occur on any line, as long as it is at the start of the line. -You can also specify specific rules to be ignored as follows: +You can also specify specific rules to be ignored as follows: ``` WIP: This is my commit message @@ -201,7 +207,7 @@ gitlint-ignore: T1, body-hard-tab gitlint configuration is applied in the following order of precedence: 1. Commit specific config (e.g.: `gitlint-ignore: all` in the commit message) -2. Configuration Rules (e.g.: [ignore-by-title](/rules/#i1-ignore-by-title)) +2. Configuration Rules (e.g.: [ignore-by-title](rules.md#i1-ignore-by-title)) 3. Commandline convenience flags (e.g.: `-vv`, `--silent`, `--ignore`) 4. Environment variables (e.g.: `GITLINT_VERBOSITY=3`) 5. Commandline configuration flags (e.g.: `-c title-max-length=123`) @@ -216,9 +222,9 @@ using commandline flags or in `[general]` section in a `.gitlint` configuration Enable silent mode (no output). Use [exit](index.md#exit-codes) code to determine result. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- -`False` | >= 0.1.0 | `--silent` | `GITLINT_SILENT` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| `False` | >= 0.1.0 | `--silent` | `GITLINT_SILENT` | #### Examples ```sh @@ -226,14 +232,15 @@ Default value | gitlint version | commandline flag | environment variable gitlint --silent GITLINT_SILENT=1 gitlint # using env variable ``` +------------------------------------------------------------------------------------------------------------------------ ### verbosity Amount of output gitlint will show when printing errors. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- -3 | >= 0.1.0 | `-v` | `GITLINT_VERBOSITY` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| 3 | >= 0.1.0 | `-v` | `GITLINT_VERBOSITY` | #### Examples @@ -252,14 +259,15 @@ GITLINT_VERBOSITY=2 gitlint # using env variable [general] verbosity=2 ``` +------------------------------------------------------------------------------------------------------------------------ ### ignore Comma separated list of rules to ignore (by name or id). -Default value | gitlint version | commandline flag | environment variable ----------------------------|------------------|-------------------|----------------------- - [] (=empty list) | >= 0.1.0 | `--ignore` | `GITLINT_IGNORE` +| Default value | gitlint version | commandline flag | environment variable | +| ---------------- | --------------- | ---------------- | -------------------- | +| [] (=empty list) | >= 0.1.0 | `--ignore` | `GITLINT_IGNORE` | #### Examples ```sh @@ -274,14 +282,15 @@ GITLINT_IGNORE=T1,body-min-length gitlint # using env variable [general] ignore=T1,body-min-length ``` +------------------------------------------------------------------------------------------------------------------------ ### debug Enable debugging output. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - false | >= 0.7.1 | `--debug` | `GITLINT_DEBUG` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| false | >= 0.7.1 | `--debug` | `GITLINT_DEBUG` | #### Examples ```sh @@ -291,14 +300,15 @@ GITLINT_DEBUG=1 gitlint # using env variable # --debug is special, the following does NOT work # gitlint -c general.debug=true ``` +------------------------------------------------------------------------------------------------------------------------ ### target Target git repository gitlint should be linting against. -Default value | gitlint version | commandline flag | environment variable ----------------------------|------------------|-------------------|----------------------- -(empty) | >= 0.8.0 | `--target` | `GITLINT_TARGET` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| (empty) | >= 0.8.0 | `--target` | `GITLINT_TARGET` | #### Examples ```sh @@ -312,14 +322,31 @@ GITLINT_TARGET=/home/joe/myrepo/ gitlint # using env variable [general] target=/home/joe/myrepo/ ``` +------------------------------------------------------------------------------------------------------------------------ + +### config + +Path where gitlint looks for a config file. + +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| `.gitlint` | >= 0.1.0 | `--config` | `GITLINT_CONFIG` | + +#### Examples +```sh +gitlint --config=/home/joe/gitlint.ini +gitlint -C /home/joe/gitlint.ini # different way of doing the same +GITLINT_CONFIG=/home/joe/gitlint.ini # using env variable +``` +------------------------------------------------------------------------------------------------------------------------ ### extra-path Path where gitlint looks for [user-defined rules](user_defined_rules.md). -Default value | gitlint version | commandline flag | environment variable ----------------------------|------------------|-------------------|----------------------- - (empty) | >= 0.8.0 | `--extra-path` | `GITLINT_EXTRA_PATH` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| (empty) | >= 0.8.0 | `--extra-path` | `GITLINT_EXTRA_PATH` | #### Examples ```sh @@ -333,14 +360,14 @@ GITLINT_EXTRA_PATH=/home/joe/rules/ gitlint # using env variable [general] extra-path=/home/joe/rules/ ``` - +------------------------------------------------------------------------------------------------------------------------ ### contrib -Comma-separated list of [Contrib rules](contrib_rules) to enable (by name or id). +Comma-separated list of [Contrib rules](contrib_rules.md) to enable (by name or id). -Default value | gitlint version | commandline flag | environment variable ----------------------------|------------------|-------------------|----------------------- - (empty) | >= 0.12.0 | `--contrib` | `GITLINT_CONTRIB` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| (empty) | >= 0.12.0 | `--contrib` | `GITLINT_CONTRIB` | #### Examples ```sh @@ -349,21 +376,31 @@ gitlint --contrib=contrib-title-conventional-commits,CC1 # different way of doing the same gitlint -c general.contrib=contrib-title-conventional-commits,CC1 # using env variable -GITLINT_CONTRIB=contrib-title-conventional-commits,CC1 gitlint +GITLINT_CONTRIB=contrib-title-conventional-commits,CC1 gitlint ``` ```ini #.gitlint [general] contrib=contrib-title-conventional-commits,CC1 ``` +------------------------------------------------------------------------------------------------------------------------ ### staged -Fetch additional meta-data from the local repository when manually passing a commit message to gitlint via stdin or `--commit-msg`. +Attempt smart guesses about meta info (like author name, email, branch, changed files, etc) when manually passing a +commit message to gitlint via stdin or `--commit-msg`. + +Since in such cases no actual git commit exists (yet) for the message being linted, gitlint +needs to apply some heuristics (like checking `git config` and any staged changes) to make a smart guess about what the +likely author name, email, commit date, changed files and branch of the ensuing commit would be. + +When not using the `--staged` flag while linting a commit message via stdin or `--commit-msg`, gitlint will only have +access to the commit message itself for linting and won't be able to enforce rules like +[M1:author-valid-email](rules.md#m1-author-valid-email). -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - false | >= 0.13.0 | `--staged` | `GITLINT_STAGED` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| false | >= 0.13.0 | `--staged` | `GITLINT_STAGED` | #### Examples ```sh @@ -377,6 +414,7 @@ GITLINT_STAGED=1 gitlint # using env variable [general] staged=true ``` +------------------------------------------------------------------------------------------------------------------------ ### fail-without-commits @@ -384,15 +422,15 @@ Hard fail when the target commit range is empty. Note that gitlint will already fail by default on invalid commit ranges. This option is specifically to tell gitlint to fail on **valid but empty** commit ranges. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|---------------------------|----------------------- - false | >= 0.15.2 | `--fail-without-commits` | `GITLINT_FAIL_WITHOUT_COMMITS` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ------------------------ | ------------------------------ | +| false | >= 0.15.2 | `--fail-without-commits` | `GITLINT_FAIL_WITHOUT_COMMITS` | #### Examples ```sh # CLI # The following will cause gitlint to hard fail (i.e. exit code > 0) -# since HEAD..HEAD is a valid but empty commit range. +# since HEAD..HEAD is a valid but empty commit range. gitlint --fail-without-commits --commits HEAD..HEAD GITLINT_FAIL_WITHOUT_COMMITS=1 gitlint # using env variable ``` @@ -402,13 +440,79 @@ GITLINT_FAIL_WITHOUT_COMMITS=1 gitlint # using env variable fail-without-commits=true ``` +--- +### regex-style-search + +Whether to use Python `re.search()` instead of `re.match()` semantics in all built-in rules that use regular expressions. + +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| false | >= 0.18.0 | Not Available | Not Available | + +!!! important + At this time, `regex-style-search` is **disabled** by default, but it will be **enabled** by default in the future. + + + +Gitlint will log a warning when you're using a rule that uses a custom regex and this option is not enabled: + +```plain +WARNING: I1 - ignore-by-title: gitlint will be switching from using Python regex 'match' (match beginning) to +'search' (match anywhere) semantics. Please review your ignore-by-title.regex option accordingly. +To remove this warning, set general.regex-style-search=True. +More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search +``` + +*If you don't have any custom regex specified, gitlint will not log a warning and no action is needed.* + +**To remove the warning:** + +1. Review your regex in the rules gitlint warned for and ensure it's still accurate when using [`re.search()` semantics](https://docs.python.org/3/library/re.html#search-vs-match). +2. Enable `regex-style-search` in your `.gitlint` file (or using [any other way to configure gitlint](http://127.0.0.1:8000/gitlint/configuration/)): + +```ini +[general] +regex-style-search=true +``` + +#### More context +Python offers [two different primitive operations based on regular expressions](https://docs.python.org/3/library/re.html#search-vs-match): +`re.match()` checks for a match only at the beginning of the string, while `re.search()` checks for a match anywhere +in the string. + + + +Most rules in gitlint already use `re.search()` instead of `re.match()`, but there's a few notable exceptions that +use `re.match()`, which can lead to unexpected matching behavior. + +- M1 - author-valid-email +- I1 - ignore-by-title +- I2 - ignore-by-body +- I3 - ignore-body-lines +- I4 - ignore-by-author-name + +The `regex-style-search` option is meant to fix this inconsistency. Setting it to `true` will force the above rules to +use `re.search()` instead of `re.match()`. For detailed context, see [issue #254](https://github.com/jorisroovers/gitlint/issues/254). + + +#### Examples +```sh +# CLI +gitlint -c general.regex-style-search=true +``` +```ini +#.gitlint +[general] +regex-style-search=true +``` +------------------------------------------------------------------------------------------------------------------------ ### ignore-stdin Ignore any stdin data. Sometimes useful when running gitlint in a CI server. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - false | >= 0.12.0 | `--ignore-stdin` | `GITLINT_IGNORE_STDIN` +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | ---------------------- | +| false | >= 0.12.0 | `--ignore-stdin` | `GITLINT_IGNORE_STDIN` | #### Examples ```sh @@ -422,14 +526,15 @@ GITLINT_IGNORE_STDIN=1 gitlint # using env variable [general] ignore-stdin=true ``` +------------------------------------------------------------------------------------------------------------------------ ### ignore-merge-commits Whether or not to ignore merge commits. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - true | >= 0.7.0 | Not Available | Not Available +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| true | >= 0.7.0 | Not Available | Not Available | #### Examples ```sh @@ -441,14 +546,15 @@ gitlint -c general.ignore-merge-commits=false [general] ignore-merge-commits=false ``` +------------------------------------------------------------------------------------------------------------------------ ### ignore-revert-commits Whether or not to ignore revert commits. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - true | >= 0.13.0 | Not Available | Not Available +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| true | >= 0.13.0 | Not Available | Not Available | #### Examples ```sh @@ -460,14 +566,15 @@ gitlint -c general.ignore-revert-commits=false [general] ignore-revert-commits=false ``` +------------------------------------------------------------------------------------------------------------------------ ### ignore-fixup-commits Whether or not to ignore [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - true | >= 0.9.0 | Not Available | Not Available +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| true | >= 0.9.0 | Not Available | Not Available | #### Examples ```sh @@ -479,14 +586,35 @@ gitlint -c general.ignore-fixup-commits=false [general] ignore-fixup-commits=false ``` +------------------------------------------------------------------------------------------------------------------------ + +### ignore-fixup-amend-commits + +Whether or not to ignore [fixup=amend](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt) commits. + +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| true | >= 0.18.0 | Not Available | Not Available | + +#### Examples +```sh +# CLI +gitlint -c general.ignore-fixup-amend-commits=false +``` +```ini +#.gitlint +[general] +ignore-fixup-amend-commits=false +``` +------------------------------------------------------------------------------------------------------------------------ ### ignore-squash-commits Whether or not to ignore [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) commits. -Default value | gitlint version | commandline flag | environment variable ----------------|------------------|-------------------|----------------------- - true | >= 0.9.0 | Not Available | Not Available +| Default value | gitlint version | commandline flag | environment variable | +| ------------- | --------------- | ---------------- | -------------------- | +| true | >= 0.9.0 | Not Available | Not Available | #### Examples ```sh diff --git a/docs/contrib_rules.md b/docs/contrib_rules.md index 336e42a..e085f23 100644 --- a/docs/contrib_rules.md +++ b/docs/contrib_rules.md @@ -1,11 +1,12 @@ # Using Contrib Rules + _Introduced in gitlint v0.12.0_ Contrib rules are community-**contrib**uted rules that are disabled by default, but can be enabled through configuration. Contrib rules are meant to augment default gitlint behavior by providing users with rules for common use-cases without forcing these rules on all gitlint users. This also means that users don't have to -re-implement these commonly used rules themselves as [user-defined](user_defined_rules) rules. +re-implement these commonly used rules themselves as [user-defined](user_defined_rules.md) rules. To enable certain contrib rules, you can use the `--contrib` flag. ```sh @@ -42,6 +43,8 @@ ID | Name | gitlint version | Description ------|-------------------------------------|------------------ |------------------------------------------- CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [Conventional Commits](https://www.conventionalcommits.org/) commit message style on the title. CC1 | contrib-body-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-off-by` line. +CC2 | contrib-disallow-cleanup-commits | >= 0.18.0 | Commit title must not contain `fixup!`, `squash!`, `amend!`. +CC3 | contrib-allowed-authors | >= 0.18.0 | Enforce that only authors listed in the `AUTHORS` file are allowed to commit. ## CT1: contrib-title-conventional-commits ## @@ -63,5 +66,18 @@ ID | Name | gitlint version | Description CC1 | contrib-body-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-off-by` line. This means, a line that starts with the `Signed-off-by` keyword. +## CC2: contrib-disallow-cleanup-commits ## + +ID | Name | gitlint version | Description +------|----------------------------------|--------------------|------------------------------------------- +CC2 | contrib-disallow-cleanup-commits | >= 0.18.0 | Commit title must not contain `fixup!`, `squash!` or `amend!`. This means `git commit --fixup` and `git commit --squash` commits are not allowed. + +## CC3: contrib-allowed-authors ## + +ID | Name | gitlint version | Description +------|----------------------------------|--------------------|------------------------------------------- +CC3 | contrib-allowed-authors | >= 0.18.0 | The commit author must be listed in an `AUTHORS` file to be allowed to commit. Possible file names are also `AUTHORS.txt` and `AUTHORS.md`. + ## Contributing Contrib rules -We'd love for you to contribute new Contrib rules to gitlint or improve existing ones! Please visit the [Contributing](contributing) page on how to get started. + +We'd love for you to contribute new Contrib rules to gitlint or improve existing ones! Please visit the [Contributing](contributing.md) page on how to get started. diff --git a/docs/contributing.md b/docs/contributing.md index 1002676..254e856 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -6,7 +6,7 @@ The [source-code and issue tracker](https://github.com/jorisroovers/gitlint) are Often it takes a while for us (well, actually just [me](https://github.com/jorisroovers)) to get back to you (sometimes up to a few months, this is a hobby project), but rest assured that we read your message and appreciate your interest! -We maintain a [loose roadmap on our wiki](https://github.com/jorisroovers/gitlint/wiki/Roadmap), but +We maintain a [loose project plan on github projects](https://github.com/users/jorisroovers/projects/1/), but that's open to a lot of change and input. ## Guidelines @@ -19,11 +19,15 @@ When contributing code, please consider all the parts that are typically require - [Integration tests](https://github.com/jorisroovers/gitlint/tree/main/qa) (also automatically [enforced by CI](https://github.com/jorisroovers/gitlint/actions)). Again, please consider writing new ones for your functionality, not only updating existing ones to make the build pass. -- [Documentation](https://github.com/jorisroovers/gitlint/tree/main/docs) +- [Documentation](https://github.com/jorisroovers/gitlint/tree/main/docs). Since we want to maintain a high standard of quality, all of these things will have to be done regardless before code -can make it as part of a release. If you can already include them as part of your PR, it's a huge timesaver for us -and it's likely that your PR will be merged and released a lot sooner. Thanks! +can make it as part of a release. **Gitlint commits and pull requests are gated on all of our tests and checks as well as +code-review**. If you can already include them as part of your PR, it's a huge timesaver for us +and it's likely that your PR will be merged and released a lot sooner. + +It's also a good idea to open an issue before submitting a PR for non-trivial changes, so we can discuss what you have +in mind before you spend the effort. Thanks! !!! Important **On the topic of releases**: Gitlint releases typically go out when there's either enough new features and fixes @@ -32,55 +36,105 @@ and it's likely that your PR will be merged and released a lot sooner. Thanks! or months before merged code actually gets released - we know that can be frustrating but please understand it's a well-considered trade-off based on available time. -## Development +## Local setup -There is a Vagrantfile (Ubuntu) in this repository that can be used for development. -It comes pre-installed with all Python versions that gitlint supports. -```sh -vagrant up -vagrant ssh -``` - -Or you can choose to use your local environment: +To install gitlint for local development: ```sh python -m venv .venv . .venv/bin/activate -pip install --upgrade pip pip install -r requirements.txt -r test-requirements.txt -r doc-requirements.txt python setup.py develop ``` -To run tests: +## Github Devcontainer + +We provide a devcontainer on github to make it easier to get started with gitlint development using VSCode. + +To start one, click the plus button under the *Code* dropdown on +[the gitlint repo on github](https://github.com/jorisroovers/gitlint). + +**It can take ~15min for all post installation steps to finish.** + +![Gitlint Dev Container Instructions](images/dev-container.png) + + +After setup has finished, you should be able to just activate the virtualenv in the home dir and run the tests: +```sh +. ~/.venv/bin/activate +./run_tests.sh +``` + +By default we have python 3.11 installed in the dev container, but you can also use [asdf](https://asdf-vm.com/) +(preinstalled) to install additional python versions: + +```sh +# Ensure ASDF overrides system python in PATH +# You can also append this line to your ~/.bash_profile in the devcontainer to have this happen automatically on login +source "$(brew --prefix asdf)/libexec/asdf.sh" + +# Install python 3.9.15 +asdf install python 3.9.15 +# List all available python versions +asdf list all python +# List installed python versions +asdf list python +``` + +## Running tests ```sh ./run_tests.sh # run unit tests and print test coverage -./run_tests.sh gitlint/tests/rules/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test +./run_tests.sh gitlint-core/gitlint/tests/rules/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test +pytest -k test_body_missing # Alternative way to run a specific test by invoking pytest directly with a keyword expression ./run_tests.sh --no-coverage # run unit tests without test coverage ./run_tests.sh --collect-only --no-coverage # Only collect, don't run unit tests ./run_tests.sh --integration # Run integration tests (requires that you have gitlint installed) ./run_tests.sh --build # Run build tests (=build python package) -./run_tests.sh --pep8 # pep8 checks +./run_tests.sh --format # format checks (black) ./run_tests.sh --stats # print some code stats ./run_tests.sh --git # inception: run gitlint against itself ./run_tests.sh --lint # run pylint checks -./run_tests.sh --all # Run unit, integration, pep8 and gitlint checks +./run_tests.sh --all # Run unit, integration, format and gitlint checks +``` +## Formatting + +We use [black](https://black.readthedocs.io/en/stable/) for code formatting. +To use it, just run black against the code you modified: + +```sh +black . # format all python code +black gitlint-core/gitlint/lint.py # format a specific file ``` -The `Vagrantfile` comes with `virtualenv`s for python 3.6, 3.7, 3.8, 3.9 and pypy3.6. -You can easily run tests against specific python environments by using the following commands *inside* of the Vagrant VM: +## Documentation +We use [mkdocs](https://www.mkdocs.org/) for generating our documentation from markdown. + +To use it: ```sh -./run_tests.sh --envs 36 # Run the unit tests against Python 3.6 -./run_tests.sh --envs 36,37,pypy36 # Run the unit tests against Python 3.6, Python 3.7 and Pypy3.6 -./run_tests.sh --envs 36,37 --pep8 # Run pep8 checks against Python 3.6 and Python 3.7 (also works for --git, --integration, --pep8, --stats and --lint. -./run_tests.sh --envs all --all # Run all tests against all environments -./run_tests.sh --all-env --all # Idem: Run all tests against all environments +pip install -r doc-requirements.txt # install doc requirements +mkdocs serve ``` -!!! important - Gitlint commits and pull requests are gated on all of our tests and checks. +Then access the documentation website on [http://localhost:8000](). ## Packaging +Gitlint consists of 2 python packages: [gitlint](https://pypi.org/project/gitlint/) +and [gitlint-core](https://pypi.org/project/gitlint-core/). + +The `gitlint` package is just a wrapper package around `gitlint-core[trusted-deps]` which strictly pins gitlint +dependencies to known working versions. + +There are scenarios where users (or OS package managers) may want looser dependency requirements. +In these cases, users can just install `gitlint-core` directly (`pip install gitlint-core`). + +[Issue 162](https://github.com/jorisroovers/gitlint/issues/162) has all the background of how we got to the decision +to split gitlint in 2 packages. + +![Gitlint package structure](images/gitlint-packages.png) + +### Packaging description + To see the package description in HTML format ```sh pip install docutils @@ -89,16 +143,6 @@ export LANG=en_US.UTF-8 python setup.py --long-description | rst2html.py > output.html ``` -## Documentation -We use [mkdocs](https://www.mkdocs.org/) for generating our documentation from markdown. - -To use it, do the following outside of the vagrant box (on your host machine): -```sh -pip install -r doc-requirements.txt # install doc requirements -mkdocs serve -``` - -Then access the documentation website on your host machine on [http://localhost:8000](). ## Tools We keep a small set of scripts in the `tools/` directory: @@ -110,13 +154,13 @@ tools/windows/run_tests.bat # Windows run unit tests ``` ## Contrib rules -Since gitlint 0.12.0, we support [Contrib rules](../contrib_rules): community contributed rules that are part of gitlint +Since gitlint 0.12.0, we support [Contrib rules](contrib_rules.md): community contributed rules that are part of gitlint itself. Thanks for considering to add a new one to gitlint! Before starting, please read all the other documentation on this page about contributing first. Then, we suggest taking the following approach to add a Contrib rule: -1. **Write your rule as a [user-defined rule](../user_defined_rules)**. In terms of code, Contrib rules are identical to +1. **Write your rule as a [user-defined rule](user_defined_rules.md)**. In terms of code, Contrib rules are identical to user-defined rules, they just happen to have their code sit within the gitlint codebase itself. 2. **Add your user-defined rule to gitlint**. You should put your file(s) in the [gitlint/contrib/rules](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/contrib/rules) directory. 3. **Write unit tests**. The gitlint codebase contains [Contrib rule test files you can copy and modify](https://github.com/jorisroovers/gitlint/tree/main/gitlint-core/gitlint/tests/contrib/rules). @@ -129,7 +173,7 @@ If you follow the steps above and follow the existing gitlint conventions wrt na In case you're looking for a slightly more formal spec, here's what gitlint requires of Contrib rules. -- Since Contrib rules are really just user-defined rules that live within the gitlint code-base, all the [user-rule requirements](../user_defined_rules/#rule-requirements) also apply to Contrib rules. +- Since Contrib rules are really just user-defined rules that live within the gitlint code-base, all the [user-rule requirements](user_defined_rules.md#rule-requirements) also apply to Contrib rules. - All contrib rules **must** have associated unit tests. We *sort of* enforce this by a unit test that verifies that there's a test file for each contrib file. - All contrib rules **must** have names that start with `contrib-`. This is to easily distinguish them from default gitlint rules. @@ -137,4 +181,4 @@ In case you're looking for a slightly more formal spec, here's what gitlint requ - All contrib rules **must** have unique names and ids. - You **can** add multiple rule classes to the same file, but classes **should** be logically grouped together in a single file that implements related rules. - Contrib rules **should** be meaningfully different from one another. If a behavior change or tweak can be added to an existing rule by adding options, that should be considered first. However, large [god classes](https://en.wikipedia.org/wiki/God_object) that implement multiple rules in a single class should obviously also be avoided. -- Contrib rules **should** use [options](../user_defined_rules/#options) to make rules configurable. +- Contrib rules **should** use [options](user_defined_rules.md#options) to make rules configurable. diff --git a/docs/demos/asciicinema.json b/docs/demos/asciicinema.json index c6e2747..a5664c7 100644 --- a/docs/demos/asciicinema.json +++ b/docs/demos/asciicinema.json @@ -1448,7 +1448,7 @@ ], [ 0.002767, - "\u001b[1;1H\u001b[93m 1 \r\n 2 \u001b[m\u001b[96m# Please enter the commit message for your changes. Lines starting\u001b[m\r\n\u001b[93m 3 \u001b[m\u001b[96m# with '#' will be ignored, and an empty message aborts the commit.\u001b[m\r\n\u001b[93m 4 \u001b[m\u001b[96m# On branch \u001b[m\u001b[38;5;224mmaster\u001b[m\r\n\u001b[93m 5 \u001b[m\u001b[96m# \u001b[m\u001b[38;5;81mChanges to be committed:\u001b[m\r\n\u001b[93m 6 \u001b[m\u001b[96m# \u001b[m\u001b[38;5;121mnew file\u001b[m\u001b[96m: \u001b[m\u001b[95m foo.txt\u001b[m\r\n\u001b[93m 7 \u001b[m\u001b[96m#\u001b[m\r\n\u001b[94m~ \u001b[9;1H~ \u001b[10;1H~ \u001b[11;1H~ \u001b[12;1H~ \u001b[13;1H~ " + "\u001b[1;1H\u001b[93m 1 \r\n 2 \u001b[m\u001b[96m# Please enter the commit message for your changes. Lines starting\u001b[m\r\n\u001b[93m 3 \u001b[m\u001b[96m# with '#' will be ignored, and an empty message aborts the commit.\u001b[m\r\n\u001b[93m 4 \u001b[m\u001b[96m# On branch \u001b[m\u001b[38;5;224mmain\u001b[m\r\n\u001b[93m 5 \u001b[m\u001b[96m# \u001b[m\u001b[38;5;81mChanges to be committed:\u001b[m\r\n\u001b[93m 6 \u001b[m\u001b[96m# \u001b[m\u001b[38;5;121mnew file\u001b[m\u001b[96m: \u001b[m\u001b[95m foo.txt\u001b[m\r\n\u001b[93m 7 \u001b[m\u001b[96m#\u001b[m\r\n\u001b[94m~ \u001b[9;1H~ \u001b[10;1H~ \u001b[11;1H~ \u001b[12;1H~ \u001b[13;1H~ " ], [ 0.000062, @@ -2404,7 +2404,7 @@ ], [ 0.052844, - "1: T3 Title has trailing punctuation (!): \"WIP: This is an patchset that I need to continue working on!\"\r\n1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is an patchset that I need to continue working on!\"\r\n3: B6 Body message is missing\r\n" + "1: T3 Title has trailing punctuation (!): \"WIP: This is a patchset that I need to continue working on!\"\r\n1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is a patchset that I need to continue working on!\"\r\n3: B6 Body message is missing\r\n" ], [ 0.006075, @@ -2432,7 +2432,7 @@ ], [ 0.004763, - "[master 4b1f92d] WIP: This is an patchset that I need to continue working on!\r\n" + "[main 4b1f92d] WIP: This is a patchset that I need to continue working on!\r\n" ], [ 0.001504, @@ -3108,11 +3108,11 @@ ], [ 0.050694, - "1: T1 Title exceeds max length (60\u003e50): \"WIP: This is an patchset that I need to continue working on!\"\r\n" + "1: T1 Title exceeds max length (60\u003e50): \"WIP: This is a patchset that I need to continue working on!\"\r\n" ], [ 0.000006, - "1: T3 Title has trailing punctuation (!): \"WIP: This is an patchset that I need to continue working on!\"\r\n1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is an patchset that I need to continue working on!\"\r\n3: B6 Body message is missing\r\n" + "1: T3 Title has trailing punctuation (!): \"WIP: This is a patchset that I need to continue working on!\"\r\n1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is a patchset that I need to continue working on!\"\r\n3: B6 Body message is missing\r\n" ], [ 0.005418, @@ -3508,7 +3508,7 @@ ], [ 0.050989, - "1: T1 Title exceeds max length (60\u003e50): \"WIP: This is an patchset that I need to continue working on!\"\r\n1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is an patchset that I need to continue working on!\"\r\n" + "1: T1 Title exceeds max length (60\u003e50): \"WIP: This is a patchset that I need to continue working on!\"\r\n1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is a patchset that I need to continue working on!\"\r\n" ], [ 0.000025, @@ -3795,4 +3795,4 @@ "exit\r\n" ] ] -} +} \ No newline at end of file diff --git a/docs/extra.css b/docs/extra.css index 5643925..12a7663 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -2,3 +2,11 @@ a.toctree-l3 { margin-left: 10px; /* display: none; */ } + +.wy-nav-content { + max-width: 1000px; +} + +.document hr { + border-top: 1px solid #666; +} \ No newline at end of file diff --git a/docs/images/dev-container.png b/docs/images/dev-container.png new file mode 100644 index 0000000..6cac5a2 Binary files /dev/null and b/docs/images/dev-container.png differ diff --git a/docs/images/gitlint-packages.drawio.svg b/docs/images/gitlint-packages.drawio.svg new file mode 100644 index 0000000..6098e3d --- /dev/null +++ b/docs/images/gitlint-packages.drawio.svg @@ -0,0 +1,351 @@ + + + + + + + +
+
+
+ + gitlint-core + +
+
+
+
+ + gitlint-core + +
+
+ + + + + +
+
+
+ + + trusted-deps + + +
+
+
+
+ + trusted-deps + +
+
+ + + + +
+
+
+ + extra_requires + +
+
+
+
+ + extra_requires + +
+
+ + + + +
+
+
+ + install_requires + +
+
+
+
+ + install_requires + +
+
+ + + + +
+
+
+ Source Code, CLI entry point, etc +
+
+
+
+ + Source Code, CLI entry point, etc + +
+
+ + + + +
+
+
+
+ Click==8.0.3 +
+ + arrow==1.2.1 +
+ ... +
+
+
+
+
+
+ + Click==8.0.3... + +
+
+ + + + +
+
+
+
+ Click>=8 +
+ + arrow>=1 +
+ ... +
+
+
+
+
+
+ + Click>=8... + +
+
+ + + + +
+
+
+ PyPI package +
+
+
+
+ + PyPI package + +
+
+ + + + +
+
+
+ + gitlint + +
+
+
+
+ + gitlint + +
+
+ + + + +
+
+
+ PyPI package +
+
+
+
+ + PyPI package + +
+
+ + + + + +
+
+
+ + install_requires + +
+
+
+
+ + install_requires + +
+
+ + + + +
+
+
+ gitlint-core[ + + + trusted-deps + + + ]==0.17.0 +
+
+
+
+ + gitlint-core[trusted-deps]==0.17... + +
+
+ + + + + + + + + + +
+
+
+ + + pip install gitlint + + +
+
+
+
+ + pip install gitl... + +
+
+ + + + +
+
+
+ + + pip install gitlint-core + + +
+
+
+
+ + pip install gitlint-c... + +
+
+ + + + +
+
+
+ + Use strict dependencies (most users) + +
+
+
+
+ + Use strict dependencies (m... + +
+
+ + + + +
+
+
+ + Use loose dependencies +
+ (at your risk) +
+
+
+
+
+ + Use loose dependencies... + +
+
+ + + + + + + + +
+ + + + + Viewer does not support full SVG 1.1 + + + +
\ No newline at end of file diff --git a/docs/images/gitlint-packages.png b/docs/images/gitlint-packages.png new file mode 100644 index 0000000..00d3ec1 Binary files /dev/null and b/docs/images/gitlint-packages.png differ diff --git a/docs/index.md b/docs/index.md index 398b4e5..801a16e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,11 +22,11 @@ Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or - **Easily integrated**: Gitlint is designed to work [with your own scripts or CI system](#using-gitlint-in-a-ci-environment). - **Sane defaults:** Many of gitlint's validations are based on [well-known](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), -[community](http://addamhardy.com/2013/06/05/good-commit-messages-and-enforcing-them-with-git-hooks.html), +[community](https://addamhardy.com/2013-06-05-good-commit-messages-and-enforcing-them-with-git-hooks), [standards](http://chris.beams.io/posts/git-commit/), others are based on checks that we've found useful throughout the years. - **Easily configurable:** Gitlint has sane defaults, but [you can also easily customize it to your own liking](configuration.md). - - **Community contributed rules**: Conventions that are common but not universal [can be selectively enabled](contrib_rules). + - **Community contributed rules**: Conventions that are common but not universal [can be selectively enabled](contrib_rules.md). - **User-defined rules:** Want to do more then what gitlint offers out of the box? Write your own [user defined rules](user_defined_rules.md). - **Full unicode support:** Lint your Russian, Chinese or Emoji commit messages with ease! - **Production-ready:** Gitlint checks a lot of the boxes you're looking for: actively maintained, high unit test coverage, integration tests, @@ -38,6 +38,10 @@ useful throughout the years. # Pip is recommended to install the latest version pip install gitlint +# Alternative: by default, gitlint is installed with pinned dependencies. +# To install gitlint with looser dependency requirements, only install gitlint-core. +pip install gitlint-core + # Community maintained packages: brew install gitlint # Homebrew (macOS) sudo port install gitlint # Macports (macOS) @@ -81,6 +85,19 @@ $ cat examples/commit-message-2 | gitlint !!! note The returned exit code equals the number of errors found. [Some exit codes are special](index.md#exit-codes). +### Shell completion + +```sh +# Bash: add to ~/.bashrc +eval "$(_GITLINT_COMPLETE=bash_source gitlint)" + +# Zsh: add to ~/.zshrc +eval "$(_GITLINT_COMPLETE=zsh_source gitlint)" + +# Fish: add to ~/.config/fish/completions/foo-bar.fish +eval (env _GITLINT_COMPLETE=fish_source gitlint) +``` + ## Configuration For in-depth documentation of general and rule-specific configuration options, have a look at the [Configuration](configuration.md) and [Rules](rules.md) pages. @@ -93,7 +110,7 @@ Short example `.gitlint` file ([full reference](configuration.md)): # their id or by their full name ignore=body-is-missing,T3 -# Ignore any data send to gitlint via stdin +# Ignore any data sent to gitlint via stdin ignore-stdin=true # Configure title-max-length rule, set title length to 80 (72 = default) @@ -136,7 +153,8 @@ Options: (e.g.: -c T1.line-length=80). Flag can be used multiple times to set multiple config values. --commit TEXT Hash (SHA) of specific commit to lint. - --commits TEXT The range of commits to lint. [default: HEAD] + --commits TEXT The range of commits (refspec or comma-separated + hashes) to lint. [default: HEAD] -e, --extra-path PATH Path to a directory or python module with extra user-defined rules --ignore TEXT Ignore rules (comma-separated by id or name). @@ -145,8 +163,9 @@ Options: --msg-filename FILENAME Path to a file containing a commit-msg. --ignore-stdin Ignore any stdin data. Useful for running in CI server. - --staged Read staged commit meta-info from the local - repository. + --staged Attempt smart guesses about meta info (like + author name, email, branch, changed files, etc) + for staged commits. --fail-without-commits Hard fail when the target commit range is empty. -v, --verbose Verbosity, more v's for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv] @@ -218,7 +237,7 @@ In case you want to change gitlint's behavior, you should either use a `.gitlint your `.pre-commit-config.yaml` file like so: ```yaml - repo: https://github.com/jorisroovers/gitlint - rev: # Fill in a tag / sha here + rev: # Fill in a tag / sha here (e.g. v0.18.0) hooks: - id: gitlint args: [--contrib=CT1, --msg-filename] @@ -229,6 +248,36 @@ your `.pre-commit-config.yaml` file like so: You need to add `--msg-filename` at the end of your custom `args` list as the gitlint-hook will fail otherwise. +### gitlint and pre-commit in CI +gitlint also supports a `gitlint-ci` pre-commit hook that can be used in CI environments. + +Configure it like so: +```yaml +- repo: https://github.com/jorisroovers/gitlint + rev: # insert ref, e.g. v0.18.0 + hooks: + - id: gitlint # this is the regular commit-msg hook + - id: gitlint-ci # hook for CI environments +``` + +And invoke it in your CI environment like this: + +```sh +pre-commit run --hook-stage manual gitlint-ci +``` + +By default this will only lint the latest commit. +If you want to lint more commits you can modify the `gitlint-ci` hook like so: + +```yaml +- repo: https://github.com/jorisroovers/gitlint + rev: v0.17.0 + hooks: + - id: gitlint + - id: gitlint-ci + args: [--debug, --commits, mybranch] # enable debug mode, lint all commits in mybranch +``` + ## Using gitlint in a CI environment By default, when just running `gitlint` without additional parameters, gitlint lints the last commit in the current working directory. @@ -248,33 +297,48 @@ git log -1 --pretty=%B 62c0519 | gitlint Note that gitlint requires that you specify `--pretty=%B` (=only print the log message, not the metadata), future versions of gitlint might fix this and not require the `--pretty` argument. -## Linting specific commits +## Linting specific commits or branches -Gitlint allows users to lint a specific commit: +Gitlint can lint specific commits using `--commit`: ```sh gitlint --commit 019cf40580a471a3958d3c346aa8bfd265fe5e16 -gitlint --commit 019cf40 # short SHAs work too +gitlint --commit 019cf40 # short SHAs work too +gitlint --commit HEAD~2 # as do special references +gitlint --commit mybranch # lint latest commit on a branch ``` -You can also lint multiple commits at once like so: +You can also lint multiple commits using `--commits` (plural): ```sh # Lint a specific commit range: gitlint --commits "019cf40...d6bc75a" -# You can also use git's special references: +# Lint all commits on a branch +gitlint --commits mybranch +# Lint all commits that are different between a branch and your main branch +gitlint --commits "main..mybranch" +# Use git's special references gitlint --commits "origin..HEAD" + +# You can also pass multiple, comma separated commit hashes: +gitlint --commits 019cf40,c50eb150,d6bc75a +# These can include special references as well +gitlint --commits HEAD~1,mybranch-name,origin/main,d6bc75a ``` The `--commits` flag takes a **single** refspec argument or commit range. Basically, any range that is understood by [git rev-list](https://git-scm.com/docs/git-rev-list) as a single argument will work. +Alternatively, you can pass `--commits` a comma-separated list of commit hashes (both short and full-length SHAs work, +as well as special references such as `HEAD` and branch names). +Gitlint will treat these as pointers to **single** commits and lint these in the order you passed. + For cases where the `--commits` option doesn't provide the flexibility you need, you can always use a simple shell script to lint an arbitrary set of commits, like shown in the example below. ```sh #!/bin/sh -for commit in $(git rev-list master); do +for commit in $(git rev-list my-branch); do echo "Commit $commit" gitlint --commit $commit echo "--------" @@ -283,14 +347,14 @@ done !!! note One downside to this approach is that you invoke gitlint once per commit vs. once per set of commits. - This means you'll incur the gitlint startup time once per commit, making this approach rather slow if you want to + This means you'll incur the gitlint startup time once per commit, making it rather slow if you want to lint a large set of commits. Always use `--commits` if you can to avoid this performance penalty. ## Merge, fixup, squash and revert commits -_Introduced in gitlint v0.7.0 (merge), v0.9.0 (fixup, squash) and v0.13.0 (revert)_ +_Introduced in gitlint v0.7.0 (merge), v0.9.0 (fixup, squash), v0.13.0 (revert) and v0.18.0 (fixup=amend)_ -**Gitlint ignores merge, revert, fixup and squash commits by default.** +**Gitlint ignores merge, revert, fixup, and squash commits by default.** For merge and revert commits, the rationale for ignoring them is that most users keep git's default messages for these commits (i.e *Merge/Revert "[original commit message]"*). @@ -300,14 +364,14 @@ For example, a common case is that *"Merge:"* being auto-prepended triggers a [title-max-length](rules.md#t1-title-max-length) violation. Most users don't want this, so we disable linting on Merge and Revert commits by default. -For [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) and [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits, the rationale is that these are temporary +For [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) and [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) (including [fixup=amend](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)) commits, the rationale is that these are temporary commits that will be squashed into a different commit, and hence the commit messages for these commits are very -short-lived and not intended to make it into the final commit history. In addition, by prepending *"fixup!"* or -*"squash!"* to your commit message, certain gitlint rules might be violated +short-lived and not intended to make it into the final commit history. In addition, by prepending *"fixup!"*, +*"amend!"* or *"squash!"* to your commit message, certain gitlint rules might be violated (e.g. [title-max-length](rules.md#t1-title-max-length)) which is often undesirable. In case you *do* want to lint these commit messages, you can disable this behavior by setting the -general `ignore-merge-commits`, `ignore-revert-commits`, `ignore-fixup-commits` or +general `ignore-merge-commits`, `ignore-revert-commits`, `ignore-fixup-commits`, `ignore-fixup-amend-commits` or `ignore-squash-commits` option to `false` [using one of the various ways to configure gitlint](configuration.md). @@ -374,7 +438,7 @@ additional unique identifier (i.e. the rule *name*) during configuration. For example, by defining 2 `body-max-line-length` rules with different `line-length` options, you obviously create a conflicting situation. Gitlint does not do any resolution of such conflicts, it's up to you to make sure any configuration is non-conflicting. So caution advised! - + Defining a named rule is easy, for example using your `.gitlint` file: ```ini @@ -400,7 +464,7 @@ When executing gitlint, you will see the violations from the default `title-must the violations caused by the additional Named Rules. ```sh -$ gitlint +$ gitlint 1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: foo wonderwoman hur bar" 1: T5:This-Can_Be*Whatever$YouWant Title contains the word 'wonderwoman' (case-insensitive): "WIP: foo wonderwoman hur bar" 1: T5:extra-words Title contains the word 'foo' (case-insensitive): "WIP: foo wonderwoman hur bar" @@ -431,8 +495,8 @@ of violations counted by the exit code is 252. Note that gitlint does not have a it can detect, it will just always return with exit code 252 when the number of violations is greater than or equal to 252. -Exit Code | Description ------------|------------------------------------------------------------ -253 | Wrong invocation of the `gitlint` command. -254 | Something went wrong when invoking git. -255 | Invalid gitlint configuration +| Exit Code | Description | +| --------- | ------------------------------------------ | +| 253 | Wrong invocation of the `gitlint` command. | +| 254 | Something went wrong when invoking git. | +| 255 | Invalid gitlint configuration | diff --git a/docs/rules.md b/docs/rules.md index eb4b65e..a992f26 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -8,43 +8,43 @@ In addition, you can also [write your own user-defined rule](user_defined_rules. what you're looking for. -ID | Name | gitlint version | Description -------|-----------------------------|-------------------|------------------------------------------- -T1 | title-max-length | >= 0.1.0 | Title length must be < 72 chars. -T2 | title-trailing-whitespace | >= 0.1.0 | Title cannot have trailing whitespace (space or tab) -T3 | title-trailing-punctuation | >= 0.1.0 | Title cannot have trailing punctuation (?:!.,;) -T4 | title-hard-tab | >= 0.1.0 | Title cannot contain hard tab characters (\t) -T5 | title-must-not-contain-word | >= 0.1.0 | Title cannot contain certain words (default: "WIP") -T6 | title-leading-whitespace | >= 0.4.0 | Title cannot have leading whitespace (space or tab) -T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: None) -T8 | title-min-length | >= 0.14.0 | Title length must be > 5 chars. -B1 | body-max-line-length | >= 0.1.0 | Lines in the body must be < 80 chars -B2 | body-trailing-whitespace | >= 0.1.0 | Body cannot have trailing whitespace (space or tab) -B3 | body-hard-tab | >= 0.1.0 | Body cannot contain hard tab characters (\t) -B4 | body-first-line-empty | >= 0.1.0 | First line of the body (second line of commit message) must be empty -B5 | body-min-length | >= 0.4.0 | Body length must be at least 20 characters -B6 | body-is-missing | >= 0.4.0 | Body message must be specified -B7 | body-changed-file-mention | >= 0.4.0 | Body must contain references to certain files if those files are changed in the last commit -B8 | body-match-regex | >= 0.14.0 | Title must match a given regex (default: None) -M1 | author-valid-email | >= 0.9.0 | Author email address must be a valid email address -I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title -I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body -I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex -I4 | ignore-by-author-name | >= 0.16.0 | Ignore a commit based on matching its author name +| ID | Name | gitlint version | Description | +| --- | --------------------------- | --------------- | ------------------------------------------------------------------------------------------- | +| T1 | title-max-length | >= 0.1.0 | Title length must be <= 72 chars. | +| T2 | title-trailing-whitespace | >= 0.1.0 | Title cannot have trailing whitespace (space or tab) | +| T3 | title-trailing-punctuation | >= 0.1.0 | Title cannot have trailing punctuation (?:!.,;) | +| T4 | title-hard-tab | >= 0.1.0 | Title cannot contain hard tab characters (\t) | +| T5 | title-must-not-contain-word | >= 0.1.0 | Title cannot contain certain words (default: "WIP") | +| T6 | title-leading-whitespace | >= 0.4.0 | Title cannot have leading whitespace (space or tab) | +| T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: None) | +| T8 | title-min-length | >= 0.14.0 | Title length must be >= 5 chars. | +| B1 | body-max-line-length | >= 0.1.0 | Lines in the body must be <= 80 chars | +| B2 | body-trailing-whitespace | >= 0.1.0 | Body cannot have trailing whitespace (space or tab) | +| B3 | body-hard-tab | >= 0.1.0 | Body cannot contain hard tab characters (\t) | +| B4 | body-first-line-empty | >= 0.1.0 | First line of the body (second line of commit message) must be empty | +| B5 | body-min-length | >= 0.4.0 | Body length must be at least 20 characters | +| B6 | body-is-missing | >= 0.4.0 | Body message must be specified | +| B7 | body-changed-file-mention | >= 0.4.0 | Body must contain references to certain files if those files are changed in the last commit | +| B8 | body-match-regex | >= 0.14.0 | Body must match a given regex (default: None) | +| M1 | author-valid-email | >= 0.9.0 | Author email address must be a valid email address | +| I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title | +| I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body | +| I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex | +| I4 | ignore-by-author-name | >= 0.16.0 | Ignore a commit based on matching its author name | ## T1: title-max-length -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T1 | title-max-length | >= 0.1 | Title length must be < 72 chars. +| ID | Name | gitlint version | Description | +| --- | ---------------- | --------------- | ------------------------------------ | +| T1 | title-max-length | >= 0.1 | Title length must be <= 72 chars. | ### Options -Name | gitlint version | Default | Description ----------------|-----------------|---------|---------------------------------- -line-length | >= 0.2 | 72 | Maximum allowed title length +| Name | gitlint version | Default | Description | +| ----------- | --------------- | ------- | ---------------------------- | +| line-length | >= 0.2 | 72 | Maximum allowed title length | ### Examples @@ -59,39 +59,43 @@ line-length=72 [title-max-length] line-length=120 ``` +------------------------------------------------------------------------------------------------------------------------ ## T2: title-trailing-whitespace -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T2 | title-trailing-whitespace | >= 0.1 | Title cannot have trailing whitespace (space or tab) +| ID | Name | gitlint version | Description | +| --- | ------------------------- | --------------- | ---------------------------------------------------- | +| T2 | title-trailing-whitespace | >= 0.1 | Title cannot have trailing whitespace (space or tab) | +------------------------------------------------------------------------------------------------------------------------ ## T3: title-trailing-punctuation -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T3 | title-trailing-punctuation | >= 0.1 | Title cannot have trailing punctuation (?:!.,;) +| ID | Name | gitlint version | Description | +| --- | -------------------------- | --------------- | ----------------------------------------------- | +| T3 | title-trailing-punctuation | >= 0.1 | Title cannot have trailing punctuation (?:!.,;) | +------------------------------------------------------------------------------------------------------------------------ ## T4: title-hard-tab -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T4 | title-hard-tab | >= 0.1 | Title cannot contain hard tab characters (\t) +| ID | Name | gitlint version | Description | +| --- | -------------- | --------------- | --------------------------------------------- | +| T4 | title-hard-tab | >= 0.1 | Title cannot contain hard tab characters (\t) | +------------------------------------------------------------------------------------------------------------------------ ## T5: title-must-not-contain-word -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T5 | title-must-not-contain-word | >= 0.1 | Title cannot contain certain words (default: "WIP") +| ID | Name | gitlint version | Description | +| --- | --------------------------- | --------------- | --------------------------------------------------- | +| T5 | title-must-not-contain-word | >= 0.1 | Title cannot contain certain words (default: "WIP") | ### Options -Name | gitlint version | Default | Description ----------------|-----------------|---------|---------------------------------- -words | >= 0.3 | WIP | Comma-separated list of words that should not be used in the title. Matching is case insensitive +| Name | gitlint version | Default | Description | +| ----- | --------------- | ------- | ------------------------------------------------------------------------------------------------ | +| words | >= 0.3 | WIP | Comma-separated list of words that should not be used in the title. Matching is case insensitive | ### Examples @@ -102,25 +106,28 @@ words | >= 0.3 | WIP | Comma-separated list of words that [title-must-not-contain-word] words=crap,darn,damn ``` +------------------------------------------------------------------------------------------------------------------------ ## T6: title-leading-whitespace -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T6 | title-leading-whitespace | >= 0.4 | Title cannot have leading whitespace (space or tab) +| ID | Name | gitlint version | Description | +| --- | ------------------------ | --------------- | --------------------------------------------------- | +| T6 | title-leading-whitespace | >= 0.4 | Title cannot have leading whitespace (space or tab) | + +------------------------------------------------------------------------------------------------------------------------ ## T7: title-match-regex -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T7 | title-match-regex | >= 0.5 | Title must match a given regex (default: .*) +| ID | Name | gitlint version | Description | +| --- | ----------------- | --------------- | -------------------------------------------- | +| T7 | title-match-regex | >= 0.5 | Title must match a given regex (default: .*) | ### Options -Name | gitlint version | Default | Description ----------------|-----------------|---------|---------------------------------- -regex | >= 0.5 | .* | [Python regex](https://docs.python.org/library/re.html) that the title should match. +| Name | gitlint version | Default | Description | +| ----- | --------------- | ------- | ------------------------------------------------------------------------------------ | +| regex | >= 0.5 | .* | [Python regex](https://docs.python.org/library/re.html) that the title should match. | ### Examples @@ -131,19 +138,20 @@ regex | >= 0.5 | .* | [Python regex](https://docs.python. [title-match-regex] regex=^US[1-9][0-9]* ``` +------------------------------------------------------------------------------------------------------------------------ ## T8: title-min-length ## -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -T1 | title-min-length | >= | Title length must be > 5 chars. +| ID | Name | gitlint version | Description | +| --- | ---------------- | --------------- | ----------------------------------- | +| T8 | title-min-length | >= 0.14.0 | Title length must be >= 5 chars. | ### Options -Name | gitlint version | Default | Description ----------------|-----------------|---------|---------------------------------- -min-length | >= 0.14.0 | 5 | Minimum required title length +| Name | gitlint version | Default | Description | +| ---------- | --------------- | ------- | ----------------------------- | +| min-length | >= 0.14.0 | 5 | Minimum required title length | ### Examples @@ -154,18 +162,19 @@ min-length | >= 0.14.0 | 5 | Minimum required title length [title-min-length] min-length=3 ``` +------------------------------------------------------------------------------------------------------------------------ ## B1: body-max-line-length -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B1 | body-max-line-length | >= 0.1 | Lines in the body must be < 80 chars +| ID | Name | gitlint version | Description | +| --- | -------------------- | --------------- | ---------------------------------------- | +| B1 | body-max-line-length | >= 0.1 | Lines in the body must be <= 80 chars | ### Options -Name | gitlint version | Default | Description ----------------|-----------------|---------|---------------------------------- -line-length | >= 0.2 | 80 | Maximum allowed line length in the commit message body +| Name | gitlint version | Default | Description | +| ----------- | --------------- | ------- | ------------------------------------------------------ | +| line-length | >= 0.2 | 80 | Maximum allowed line length in the commit message body | ### Examples @@ -180,38 +189,43 @@ line-length=120 [body-max-line-length] line-length=72 ``` +------------------------------------------------------------------------------------------------------------------------ ## B2: body-trailing-whitespace -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B2 | body-trailing-whitespace | >= 0.1 | Body cannot have trailing whitespace (space or tab) +| ID | Name | gitlint version | Description | +| --- | ------------------------ | --------------- | --------------------------------------------------- | +| B2 | body-trailing-whitespace | >= 0.1 | Body cannot have trailing whitespace (space or tab) | +------------------------------------------------------------------------------------------------------------------------ ## B3: body-hard-tab -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B3 | body-hard-tab | >= 0.1 | Body cannot contain hard tab characters (\t) +| ID | Name | gitlint version | Description | +| --- | ------------- | --------------- | -------------------------------------------- | +| B3 | body-hard-tab | >= 0.1 | Body cannot contain hard tab characters (\t) | +------------------------------------------------------------------------------------------------------------------------ ## B4: body-first-line-empty -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B4 | body-first-line-empty | >= 0.1 | First line of the body (second line of commit message) must be empty +| ID | Name | gitlint version | Description | +| --- | --------------------- | --------------- | -------------------------------------------------------------------- | +| B4 | body-first-line-empty | >= 0.1 | First line of the body (second line of commit message) must be empty | + +------------------------------------------------------------------------------------------------------------------------ ## B5: body-min-length -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B5 | body-min-length | >= 0.4 | Body length must be at least 20 characters. In versions >= 0.8.0, gitlint will not count newline characters. +| ID | Name | gitlint version | Description | +| --- | --------------- | --------------- | ------------------------------------------------------------------------------------------------------------ | +| B5 | body-min-length | >= 0.4 | Body length must be at least 20 characters. In versions >= 0.8.0, gitlint will not count newline characters. | ### Options ### -Name | gitlint version | Default | Description ----------------|-----------------|---------|---------------------------------- -min-length | >= 0.4 | 20 | Minimum number of required characters in body +| Name | gitlint version | Default | Description | +| ---------- | --------------- | ------- | --------------------------------------------- | +| min-length | >= 0.4 | 20 | Minimum number of required characters in body | ### Examples @@ -226,31 +240,34 @@ min-length=5 [body-min-length] min-length=100 ``` +------------------------------------------------------------------------------------------------------------------------ ## B6: body-is-missing -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B6 | body-is-missing | >= 0.4 | Body message must be specified +| ID | Name | gitlint version | Description | +| --- | --------------- | --------------- | ------------------------------ | +| B6 | body-is-missing | >= 0.4 | Body message must be specified | ### Options -Name | gitlint version | Default | Description -----------------------|-----------------|-----------|---------------------------------- -ignore-merge-commits | >= 0.4 | true | Whether this rule should be ignored during merge commits. Allowed values: true,false. +| Name | gitlint version | Default | Description | +| -------------------- | --------------- | ------- | ------------------------------------------------------------------------------------- | +| ignore-merge-commits | >= 0.4 | true | Whether this rule should be ignored during merge commits. Allowed values: true,false. | + +------------------------------------------------------------------------------------------------------------------------ ## B7: body-changed-file-mention -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B7 | body-changed-file-mention | >= 0.4 | Body must contain references to certain files if those files are changed in the last commit +| ID | Name | gitlint version | Description | +| --- | ------------------------- | --------------- | ------------------------------------------------------------------------------------------- | +| B7 | body-changed-file-mention | >= 0.4 | Body must contain references to certain files if those files are changed in the last commit | ### Options -Name | gitlint version | Default | Description -----------------------|-----------------|--------------|---------------------------------- -files | >= 0.4 | (empty) | Comma-separated list of files that need to an explicit mention in the commit message in case they are changed. +| Name | gitlint version | Default | Description | +| ----- | --------------- | ------- | -------------------------------------------------------------------------------------------------------------- | +| files | >= 0.4 | (empty) | Comma-separated list of files that need to an explicit mention in the commit message in case they are changed. | ### Examples @@ -262,18 +279,19 @@ files | >= 0.4 | (empty) | Comma-separated list o [body-changed-file-mention] files=generated.xml,secrets.txt,private-key.pem ``` +------------------------------------------------------------------------------------------------------------------------ ## B8: body-match-regex -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -B8 | body-match-regex | >= 0.14 | Body must match a given regex +| ID | Name | gitlint version | Description | +| --- | ---------------- | --------------- | ----------------------------- | +| B8 | body-match-regex | >= 0.14 | Body must match a given regex | ### Options -Name | gitlint version | Default | Description -----------------------|-----------------|--------------|---------------------------------- -regex | >= 0.14 | None | [Python regex](https://docs.python.org/library/re.html) that the title should match. +| Name | gitlint version | Default | Description | +| ----- | --------------- | ------- | ----------------------------------------------------------------------------------- | +| regex | >= 0.14 | None | [Python regex](https://docs.python.org/library/re.html) that the body should match. | ### Examples @@ -288,12 +306,13 @@ regex=Reviewed-By:(.*)$ [body-match-regex] regex=(*.)Foo(.*) ``` +------------------------------------------------------------------------------------------------------------------------ ## M1: author-valid-email -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -M1 | author-valid-email | >= 0.8.3 | Author email address must be a valid email address +| ID | Name | gitlint version | Description | +| --- | ------------------ | --------------- | -------------------------------------------------- | +| M1 | author-valid-email | >= 0.8.3 | Author email address must be a valid email address | !!! note Email addresses are [notoriously hard to validate and the official email valid spec is often too loose for any real world application](http://stackoverflow.com/a/201378/381010). @@ -303,9 +322,9 @@ M1 | author-valid-email | >= 0.8.3 | Author email address mus ### Options -Name | gitlint version | Default | Description -----------------------|-------------------|------------------------------|---------------------------------- -regex | >= 0.9.0 | `[^@ ]+@[^@ ]+\.[^@ ]+` | [Python regex](https://docs.python.org/library/re.html) the commit author email address is matched against +| Name | gitlint version | Default | Description | +| ----- | --------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------- | +| regex | >= 0.9.0 | `[^@ ]+@[^@ ]+\.[^@ ]+` | [Python regex](https://docs.python.org/library/re.html) the commit author email address is matched against | ### Examples @@ -317,20 +336,21 @@ regex | >= 0.9.0 | `[^@ ]+@[^@ ]+\.[^@ ]+` | [Python [author-valid-email] regex=[^@]+@foo.com ``` +------------------------------------------------------------------------------------------------------------------------ ## I1: ignore-by-title -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title. +| ID | Name | gitlint version | Description | +| --- | --------------- | --------------- | -------------------------------------------- | +| I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title. | ### Options -Name | gitlint version | Default | Description -----------------------|-------------------|------------------------------|---------------------------------- -regex | >= 0.10.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against commit title. On match, the commit will be ignored. -ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. +| Name | gitlint version | Default | Description | +| ------ | --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | +| regex | >= 0.10.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against commit title. On match, the commit will be ignored. | +| ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. | ### Examples @@ -345,20 +365,21 @@ ignore=title-max-length,body-min-length # ignore all rules by setting ignore to 'all' # ignore=all ``` +------------------------------------------------------------------------------------------------------------------------ ## I2: ignore-by-body -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body. +| ID | Name | gitlint version | Description | +| --- | -------------- | --------------- | ------------------------------------------- | +| I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body. | ### Options -Name | gitlint version | Default | Description -----------------------|-------------------|------------------------------|---------------------------------- -regex | >= 0.10.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against each line of the body. On match, the commit will be ignored. -ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. +| Name | gitlint version | Default | Description | +| ------ | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| regex | >= 0.10.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against each line of the body. On match, the commit will be ignored. | +| ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. | ### Examples @@ -376,19 +397,20 @@ ignore=all regex=(.*)release(.*) ignore=T1,body-min-length,B6 ``` +------------------------------------------------------------------------------------------------------------------------ ## I3: ignore-body-lines -ID | Name | gitlint version | Description -------|-----------------------------|-----------------|------------------------------------------- -I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex. +| ID | Name | gitlint version | Description | +| --- | ----------------- | --------------- | --------------------------------------------------------- | +| I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex. | ### Options -Name | gitlint version | Default | Description -----------------------|-------------------|------------------------------|---------------------------------- -regex | >= 0.14.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against each line of the body. On match, that line will be ignored by gitlint (the rest of the body will still be linted). +| Name | gitlint version | Default | Description | +| ----- | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| regex | >= 0.14.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against each line of the body. On match, that line will be ignored by gitlint (the rest of the body will still be linted). | ### Examples @@ -407,19 +429,20 @@ regex=(^Co-Authored-By)|(^Signed-off-by) [ignore-body-lines] regex=(.*)foobar(.*) ``` +------------------------------------------------------------------------------------------------------------------------ ## I4: ignore-by-author-name -ID | Name | gitlint version | Description -------|---------------------------|-----------------|------------------------------------------- -I4 | ignore-by-author-name | >= 0.16.0 | Ignore a commit based on matching its author name. +| ID | Name | gitlint version | Description | +| --- | --------------------- | --------------- | -------------------------------------------------- | +| I4 | ignore-by-author-name | >= 0.16.0 | Ignore a commit based on matching its author name. | ### Options -Name | gitlint version | Default | Description -----------------------|-------------------|------------------------------|---------------------------------- -regex | >= 0.16.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against the commit author name. On match, the commit will be ignored. -ignore | >= 0.16.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. +| Name | gitlint version | Default | Description | +| ------ | --------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| regex | >= 0.16.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against the commit author name. On match, the commit will be ignored. | +| ignore | >= 0.16.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. | ### Examples @@ -435,4 +458,4 @@ regex=dependabot [ignore-by-author-name] regex=(.*)\[bot\](.*) ignore=T1,body-min-length,B6 -``` \ No newline at end of file +``` diff --git a/docs/user_defined_rules.md b/docs/user_defined_rules.md index f58dcc7..db21809 100644 --- a/docs/user_defined_rules.md +++ b/docs/user_defined_rules.md @@ -179,27 +179,33 @@ Both `CommitRule`s and `LineRule`s take a `commit` object in their `validate(... The table below outlines the various attributes of that commit object that can be used during validation. -Property | Type | Description --------------------------------| ---------------|------------------- -commit.message | object | Python object representing the commit message -commit.message.original | string | Original commit message as returned by git -commit.message.full | string | Full commit message, with comments (lines starting with #) removed. -commit.message.title | string | Title/subject of the commit message: the first line -commit.message.body | string[] | List of lines in the body of the commit message (i.e. starting from the second line) -commit.author_name | string | Name of the author, result of `git log --pretty=%aN` -commit.author_email | string | Email of the author, result of `git log --pretty=%aE` -commit.date | datetime | Python `datetime` object representing the time of commit -commit.is_merge_commit | boolean | Boolean indicating whether the commit is a merge commit or not. -commit.is_revert_commit | boolean | Boolean indicating whether the commit is a revert commit or not. -commit.is_fixup_commit | boolean | Boolean indicating whether the commit is a fixup commit or not. -commit.is_squash_commit | boolean | Boolean indicating whether the commit is a squash commit or not. -commit.parents | string[] | List of parent commit `sha`s (only for merge commits). -commit.changed_files | string[] | List of files changed in the commit (relative paths). -commit.branches | string[] | List of branch names the commit is part of -commit.context | object | Object pointing to the bigger git context that the commit is part of -commit.context.current_branch | string | Name of the currently active branch (of local repo) -commit.context.repository_path | string | Absolute path pointing to the git repository being linted -commit.context.commits | object[] | List of commits gitlint is acting on, NOT all commits in the repo. +| Property | Type | Description | +| -------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------ | +| commit | `GitCommit` | Python object representing the commit | +| commit.message | `GitCommitMessage` | Python object representing the commit message | +| commit.message.original | `str` | Original commit message as returned by git | +| commit.message.full | `str` | Full commit message, with comments (lines starting with #) removed. | +| commit.message.title | `str` | Title/subject of the commit message: the first line | +| commit.message.body | `str[]` | List of lines in the body of the commit message (i.e. starting from the second line) | +| commit.author_name | `str` | Name of the author, result of `git log --pretty=%aN` | +| commit.author_email | `str` | Email of the author, result of `git log --pretty=%aE` | +| commit.date | `datetime.datetime` | Python `datetime` object representing the time of commit | +| commit.is_merge_commit | `bool` | Boolean indicating whether the commit is a merge commit or not. | +| commit.is_revert_commit | `bool` | Boolean indicating whether the commit is a revert commit or not. | +| commit.is_fixup_commit | `bool` | Boolean indicating whether the commit is a fixup commit or not. | +| commit.is_fixup_amend_commit | `bool` | Boolean indicating whether the commit is a (fixup) amend commit or not. | +| commit.is_squash_commit | `bool` | Boolean indicating whether the commit is a squash commit or not. | +| commit.parents | `str[]` | List of parent commit `sha`s (only for merge commits). | +| commit.changed_files | `str[]` | List of files changed in the commit (relative paths). | +| commit.changed_files_stats | `dict[str, GitChangedFilesStats]` | Dictionary mapping the changed files to a `GitChangedFilesStats` objects | +| commit.changed_files_stats["path"].filepath | `pathlib.Path` | Relative path (compared to repo root) of the file that was changed. | +| commit.changed_files_stats["path"].additions | `int` | Number of additions in the file. | +| commit.changed_files_stats["path"].deletions | `int` | Number of deletions in the file. | +| commit.branches | `str[]` | List of branch names the commit is part of | +| commit.context | `GitContext` | Object pointing to the bigger git context that the commit is part of | +| commit.context.current_branch | `str` | Name of the currently active branch (of local repo) | +| commit.context.repository_path | `str` | Absolute path pointing to the git repository being linted | +| commit.context.commits | `GitCommit[]` | List of commits gitlint is acting on, NOT all commits in the repo. | ## Violations In order to let gitlint know that there is a violation in the commit being linted, users should have the `validate(...)` @@ -216,12 +222,12 @@ RuleViolation(rule_id, message, content=None, line_nr=None): ``` With the parameters meaning the following: -Parameter | Type | Description ---------------|---------|-------------------------------- -rule_id | string | Rule's unique string id -message | string | Short description of the violation -content | string | (optional) the violating part of commit or line -line_nr | int | (optional) line number in the commit message where the violation occurs. **Automatically set to the correct line number for `LineRule`s if not set explicitly.** +| Parameter | Type | Description | +| --------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| rule_id | `str` | Rule's unique string id | +| message | `str` | Short description of the violation | +| content | `str` | (optional) the violating part of commit or line | +| line_nr | `int` | (optional) line number in the commit message where the violation occurs. **Automatically set to the correct line number for `LineRule`s if not set explicitly.** | A typical `validate(...)` implementation for a `CommitRule` would then be as follows: ```python @@ -281,14 +287,14 @@ As `options_spec` is a list, you can obviously have multiple options per rule. T Gitlint supports a variety of different option types, all can be imported from `gitlint.options`: -Option Class | Use for -------------------|-------------- -`StrOption ` | Strings -`IntOption` | Integers. `IntOption` takes an optional `allow_negative` parameter if you want to allow negative integers. -`BoolOption` | Booleans. Valid values: `true`, `false`. Case-insensitive. -`ListOption` | List of strings. Comma separated. -`PathOption` | Directory or file path. Takes an optional `type` parameter for specifying path type (`file`, `dir` (=default) or `both`). -`RegexOption` | String representing a [Python-style regex](https://docs.python.org/library/re.html) - compiled and validated before rules are applied. +| Option Class | Use for | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| `StrOption ` | Strings | +| `IntOption` | Integers. `IntOption` takes an optional `allow_negative` parameter if you want to allow negative integers. | +| `BoolOption` | Booleans. Valid values: `true`, `false`. Case-insensitive. | +| `ListOption` | List of strings. Comma separated. | +| `PathOption` | Directory or file path. Takes an optional `type` parameter for specifying path type (`file`, `dir` (=default) or `both`). | +| `RegexOption` | String representing a [Python-style regex](https://docs.python.org/library/re.html) - compiled and validated before rules are applied. | !!! note Gitlint currently does not support options for all possible types (e.g. float, list of int, etc). diff --git a/examples/my_commit_rules.py b/examples/my_commit_rules.py index 2805501..35bb836 100644 --- a/examples/my_commit_rules.py +++ b/examples/my_commit_rules.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from gitlint.rules import CommitRule, RuleViolation from gitlint.options import IntOption, ListOption @@ -27,20 +25,20 @@ class BodyMaxLineCount(CommitRule): id = "UC1" # A rule MAY have an option_spec if its behavior should be configurable. - options_spec = [IntOption('max-line-count', 3, "Maximum body line count")] + options_spec = [IntOption("max-line-count", 3, "Maximum body line count")] def validate(self, commit): self.log.debug("BodyMaxLineCount: This will be visible when running `gitlint --debug`") line_count = len(commit.message.body) - max_line_count = self.options['max-line-count'].value + max_line_count = self.options["max-line-count"].value if line_count > max_line_count: message = f"Body contains too many lines ({line_count} > {max_line_count})" return [RuleViolation(self.id, message, line_nr=1)] class SignedOffBy(CommitRule): - """ This rule will enforce that each commit contains a "Signed-off-by" line. + """This rule will enforce that each commit contains a "Signed-off-by" line. We keep things simple here and just check whether the commit body contains a line that starts with "Signed-off-by". """ @@ -61,8 +59,8 @@ class SignedOffBy(CommitRule): class BranchNamingConventions(CommitRule): - """ This rule will enforce that a commit is part of a branch that meets certain naming conventions. - See GitFlow for real-world example of this: https://nvie.com/posts/a-successful-git-branching-model/ + """This rule will enforce that a commit is part of a branch that meets certain naming conventions. + See GitFlow for real-world example of this: https://nvie.com/posts/a-successful-git-branching-model/ """ # A rule MUST have a human friendly name @@ -72,13 +70,13 @@ class BranchNamingConventions(CommitRule): id = "UC3" # A rule MAY have an option_spec if its behavior should be configurable. - options_spec = [ListOption('branch-prefixes', ["feature/", "hotfix/", "release/"], "Allowed branch prefixes")] + options_spec = [ListOption("branch-prefixes", ["feature/", "hotfix/", "release/"], "Allowed branch prefixes")] def validate(self, commit): self.log.debug("BranchNamingConventions: This line will be visible when running `gitlint --debug`") violations = [] - allowed_branch_prefixes = self.options['branch-prefixes'].value + allowed_branch_prefixes = self.options["branch-prefixes"].value for branch in commit.branches: valid_branch_name = False diff --git a/examples/my_configuration_rules.py b/examples/my_configuration_rules.py index 7c00707..7715c0b 100644 --- a/examples/my_configuration_rules.py +++ b/examples/my_configuration_rules.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from gitlint.rules import ConfigurationRule from gitlint.options import IntOption @@ -36,7 +34,7 @@ class ReleaseConfigurationRule(ConfigurationRule): id = "UCR1" # A rule MAY have an option_spec if its behavior should be configurable. - options_spec = [IntOption('custom-verbosity', 2, "Gitlint verbosity for release commits")] + options_spec = [IntOption("custom-verbosity", 2, "Gitlint verbosity for release commits")] def apply(self, config, commit): self.log.debug("ReleaseConfigurationRule: This will be visible when running `gitlint --debug`") @@ -44,7 +42,6 @@ class ReleaseConfigurationRule(ConfigurationRule): # If the commit title starts with 'Release', we want to modify # how all subsequent rules interpret that commit if commit.message.title.startswith("Release"): - # If your Release commit messages are auto-generated, the # body might contain trailing whitespace. Let's ignore that config.ignore.append("body-trailing-whitespace") @@ -60,7 +57,7 @@ class ReleaseConfigurationRule(ConfigurationRule): # config.set_general_option(, ) config.set_general_option("verbosity", 2) # Wwe can also use custom options to make this configurable - config.set_general_option("verbosity", self.options['custom-verbosity'].value) + config.set_general_option("verbosity", self.options["custom-verbosity"].value) # Strip any lines starting with $ from the commit message # (this only affects how gitlint sees your commit message, it does diff --git a/examples/my_line_rules.py b/examples/my_line_rules.py index 3a1ef36..58b0108 100644 --- a/examples/my_line_rules.py +++ b/examples/my_line_rules.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle from gitlint.options import ListOption @@ -21,8 +19,8 @@ that fits your needs. class SpecialChars(LineRule): - """ This rule will enforce that the commit message title does not contain any of the following characters: - $^%@!*() """ + """This rule will enforce that the commit message title does not contain any of the following characters: + $^%@!*()""" # A rule MUST have a human friendly name name = "title-no-special-chars" @@ -35,15 +33,20 @@ class SpecialChars(LineRule): target = CommitMessageTitle # A rule MAY have an option_spec if its behavior should be configurable. - options_spec = [ListOption('special-chars', ['$', '^', '%', '@', '!', '*', '(', ')'], - "Comma separated list of characters that should not occur in the title")] + options_spec = [ + ListOption( + "special-chars", + ["$", "^", "%", "@", "!", "*", "(", ")"], + "Comma separated list of characters that should not occur in the title", + ) + ] def validate(self, line, _commit): self.log.debug("SpecialChars: This will be visible when running `gitlint --debug`") violations = [] # options can be accessed by looking them up by their name in self.options - for char in self.options['special-chars'].value: + for char in self.options["special-chars"].value: if char in line: msg = f"Title contains the special character '{char}'" violation = RuleViolation(self.id, msg, line) diff --git a/gitlint-core/gitlint/__init__.py b/gitlint-core/gitlint/__init__.py index fd86b3e..1317d75 100644 --- a/gitlint-core/gitlint/__init__.py +++ b/gitlint-core/gitlint/__init__.py @@ -1 +1 @@ -__version__ = "0.17.0" +__version__ = "0.18.0" diff --git a/gitlint-core/gitlint/cache.py b/gitlint-core/gitlint/cache.py index 1b6558f..b84c904 100644 --- a/gitlint-core/gitlint/cache.py +++ b/gitlint-core/gitlint/cache.py @@ -1,31 +1,31 @@ class PropertyCache: - """ Mixin class providing a simple cache. """ + """Mixin class providing a simple cache.""" def __init__(self): self._cache = {} def _try_cache(self, cache_key, cache_populate_func): - """ Tries to get a value from the cache identified by `cache_key`. - If no value is found in the cache, do a function call to `cache_populate_func` to populate the cache - and then return the value from the cache. """ + """Tries to get a value from the cache identified by `cache_key`. + If no value is found in the cache, do a function call to `cache_populate_func` to populate the cache + and then return the value from the cache.""" if cache_key not in self._cache: cache_populate_func() return self._cache[cache_key] def cache(original_func=None, cachekey=None): # pylint: disable=unused-argument - """ Cache decorator. Caches function return values. - Requires the parent class to extend and initialize PropertyCache. - Usage: - # Use function name as cache key - @cache - def myfunc(args): - ... - - # Specify cache key - @cache(cachekey="foobar") - def myfunc(args): - ... + """Cache decorator. Caches function return values. + Requires the parent class to extend and initialize PropertyCache. + Usage: + # Use function name as cache key + @cache + def myfunc(args): + ... + + # Specify cache key + @cache(cachekey="foobar") + def myfunc(args): + ... """ # Decorators with optional arguments are a bit convoluted in python, see some of the links below for details. @@ -41,6 +41,7 @@ def cache(original_func=None, cachekey=None): # pylint: disable=unused-argument def cache_func_result(): # Call decorated function and store its result in the cache args[0]._cache[cachekey] = func(*args) + return args[0]._try_cache(cachekey, cache_func_result) return wrapped diff --git a/gitlint-core/gitlint/cli.py b/gitlint-core/gitlint/cli.py index 19676b3..387072e 100644 --- a/gitlint-core/gitlint/cli.py +++ b/gitlint-core/gitlint/cli.py @@ -11,6 +11,7 @@ import click import gitlint from gitlint.lint import GitLinter from gitlint.config import LintConfigBuilder, LintConfigError, LintConfigGenerator +from gitlint.deprecation import LOG as DEPRECATED_LOG, DEPRECATED_LOG_FORMAT from gitlint.git import GitContext, GitContextError, git_version from gitlint import hooks from gitlint.shell import shell @@ -37,19 +38,29 @@ LOG = logging.getLogger("gitlint.cli") class GitLintUsageError(GitlintError): - """ Exception indicating there is an issue with how gitlint is used. """ + """Exception indicating there is an issue with how gitlint is used.""" + pass def setup_logging(): - """ Setup gitlint logging """ + """Setup gitlint logging""" + + # Root log, mostly used for debug root_log = logging.getLogger("gitlint") root_log.propagate = False # Don't propagate to child loggers, the gitlint root logger handles everything + root_log.setLevel(logging.ERROR) handler = logging.StreamHandler() formatter = logging.Formatter(LOG_FORMAT) handler.setFormatter(formatter) root_log.addHandler(handler) - root_log.setLevel(logging.ERROR) + + # Deprecated log, to log deprecation warnings + DEPRECATED_LOG.propagate = False # Don't propagate to child logger + DEPRECATED_LOG.setLevel(logging.WARNING) + deprecated_log_handler = logging.StreamHandler() + deprecated_log_handler.setFormatter(logging.Formatter(DEPRECATED_LOG_FORMAT)) + DEPRECATED_LOG.addHandler(deprecated_log_handler) def log_system_info(): @@ -62,10 +73,20 @@ def log_system_info(): def build_config( # pylint: disable=too-many-arguments - target, config_path, c, extra_path, ignore, contrib, ignore_stdin, staged, fail_without_commits, verbose, - silent, debug + target, + config_path, + c, + extra_path, + ignore, + contrib, + ignore_stdin, + staged, + fail_without_commits, + verbose, + silent, + debug, ): - """ Creates a LintConfig object based on a set of commandline parameters. """ + """Creates a LintConfig object based on a set of commandline parameters.""" config_builder = LintConfigBuilder() # Config precedence: # First, load default config or config from configfile @@ -79,33 +100,33 @@ def build_config( # pylint: disable=too-many-arguments # Finally, overwrite with any convenience commandline flags if ignore: - config_builder.set_option('general', 'ignore', ignore) + config_builder.set_option("general", "ignore", ignore) if contrib: - config_builder.set_option('general', 'contrib', contrib) + config_builder.set_option("general", "contrib", contrib) if ignore_stdin: - config_builder.set_option('general', 'ignore-stdin', ignore_stdin) + config_builder.set_option("general", "ignore-stdin", ignore_stdin) if silent: - config_builder.set_option('general', 'verbosity', 0) + config_builder.set_option("general", "verbosity", 0) elif verbose > 0: - config_builder.set_option('general', 'verbosity', verbose) + config_builder.set_option("general", "verbosity", verbose) if extra_path: - config_builder.set_option('general', 'extra-path', extra_path) + config_builder.set_option("general", "extra-path", extra_path) if target: - config_builder.set_option('general', 'target', target) + config_builder.set_option("general", "target", target) if debug: - config_builder.set_option('general', 'debug', debug) + config_builder.set_option("general", "debug", debug) if staged: - config_builder.set_option('general', 'staged', staged) + config_builder.set_option("general", "staged", staged) if fail_without_commits: - config_builder.set_option('general', 'fail-without-commits', fail_without_commits) + config_builder.set_option("general", "fail-without-commits", fail_without_commits) config = config_builder.build() @@ -113,7 +134,7 @@ def build_config( # pylint: disable=too-many-arguments def get_stdin_data(): - """ Helper function that returns data send to stdin or False if nothing is send """ + """Helper function that returns data sent to stdin or False if nothing is sent""" # STDIN can only be 3 different types of things ("modes") # 1. An interactive terminal device (i.e. a TTY -> sys.stdin.isatty() or stat.S_ISCHR) # 2. A (named) pipe (stat.S_ISFIFO) @@ -145,13 +166,17 @@ def get_stdin_data(): def build_git_context(lint_config, msg_filename, commit_hash, refspec): - """ Builds a git context based on passed parameters and order of precedence """ + """Builds a git context based on passed parameters and order of precedence""" # Determine which GitContext method to use if a custom message is passed from_commit_msg = GitContext.from_commit_msg if lint_config.staged: LOG.debug("Fetching additional meta-data from staged commit") - from_commit_msg = lambda message: GitContext.from_staged_commit(message, lint_config.target) # noqa + from_commit_msg = ( + lambda message: GitContext.from_staged_commit( # pylint: disable=unnecessary-lambda-assignment + message, lint_config.target + ) + ) # Order of precedence: # 1. Any data specified via --msg-filename @@ -168,8 +193,10 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec): return from_commit_msg(stdin_input) if lint_config.staged: - raise GitLintUsageError("The 'staged' option (--staged) can only be used when using '--msg-filename' or " - "when piping data to gitlint via stdin.") + raise GitLintUsageError( + "The 'staged' option (--staged) can only be used when using '--msg-filename' or " + "when piping data to gitlint via stdin." + ) # 3. Fallback to reading from local repository LOG.debug("No --msg-filename flag, no or empty data passed to stdin. Using the local repo.") @@ -177,11 +204,25 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec): if commit_hash and refspec: raise GitLintUsageError("--commit and --commits are mutually exclusive, use one or the other.") - return GitContext.from_local_repository(lint_config.target, refspec=refspec, commit_hash=commit_hash) + # 3.1 Linting a range of commits + if refspec: + # 3.1.1 Not real refspec, but comma-separated list of commit hashes + if "," in refspec: + commit_hashes = [hash.strip() for hash in refspec.split(",")] + return GitContext.from_local_repository(lint_config.target, commit_hashes=commit_hashes) + # 3.1.2 Real refspec + return GitContext.from_local_repository(lint_config.target, refspec=refspec) + + # 3.2 Linting a specific commit + if commit_hash: + return GitContext.from_local_repository(lint_config.target, commit_hashes=[commit_hash]) + + # 3.3 Fallback to linting the current HEAD + return GitContext.from_local_repository(lint_config.target) def handle_gitlint_error(ctx, exc): - """ Helper function to handle exceptions """ + """Helper function to handle exceptions""" if isinstance(exc, GitContextError): click.echo(exc) ctx.exit(GIT_CONTEXT_ERROR_CODE) @@ -194,7 +235,7 @@ def handle_gitlint_error(ctx, exc): class ContextObj: - """ Simple class to hold data that is passed between Click commands via the Click context. """ + """Simple class to hold data that is passed between Click commands via the Click context.""" def __init__(self, config, config_builder, commit_hash, refspec, msg_filename, gitcontext=None): self.config = config @@ -205,29 +246,34 @@ class ContextObj: self.gitcontext = gitcontext +# fmt: off @click.group(invoke_without_command=True, context_settings={'max_content_width': 120}, epilog="When no COMMAND is specified, gitlint defaults to 'gitlint lint'.") @click.option('--target', envvar='GITLINT_TARGET', type=click.Path(exists=True, resolve_path=True, file_okay=False, readable=True), help="Path of the target git repository. [default: current working directory]") -@click.option('-C', '--config', type=click.Path(exists=True, dir_okay=False, readable=True, resolve_path=True), +@click.option('-C', '--config', envvar='GITLINT_CONFIG', + type=click.Path(exists=True, dir_okay=False, readable=True, resolve_path=True), help=f"Config file location [default: {DEFAULT_CONFIG_FILE}]") @click.option('-c', multiple=True, help="Config flags in format .