1
0
Fork 0

Merging upstream version 0.19.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 06:07:32 +01:00
parent 61e6dccee9
commit 2efee3d3ab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
111 changed files with 2058 additions and 1676 deletions

View file

@ -1,6 +0,0 @@
[report]
fail_under = 97
[run]
branch = true
omit=*dist-packages*,*site-packages*,gitlint-core/gitlint/tests/*,.venv/*,*virtualenv*

View file

@ -22,7 +22,11 @@
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--config",
"./pyproject.toml"
],
"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",
@ -31,12 +35,13 @@
"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"
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"tamasfe.even-better-toml"
]
}
},

View file

@ -1,6 +1,7 @@
#!/bin/sh -x
brew install asdf
brew install hatch
source "$(brew --prefix asdf)/libexec/asdf.sh"
# Install latest python

View file

@ -12,3 +12,7 @@ updates:
directory: /
schedule:
interval: daily
- package-ecosystem: pip
directory: /gitlint-core
schedule:
interval: daily

View file

@ -1,155 +0,0 @@
name: Tests and Checks
on: [push, pull_request]
jobs:
checks:
runs-on: "ubuntu-latest"
strategy:
matrix:
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@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.
# 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@v4.2.0
with:
python-version: ${{ matrix.python-version }}
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: Unit Tests
run: ./run_tests.sh
# Coveralls integration doesn't properly work at this point, also see below
# - name: Coveralls
# env:
# 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 <args>` with `script -e -q -c "gitlint <args>"`
sed -i -E 's/^gitlint(.*)/script -e -q -c "\0"/' gitlint-core/gitlint/files/commit-msg
- name: Integration Tests
run: ./run_tests.sh -i
# 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: 1
run: ./run_tests.sh -i
- name: Code formatting (black)
run: ./run_tests.sh -f
- name: PyLint
run: ./run_tests.sh -l
- name: Build tests
run: ./run_tests.sh --build
# Coveralls GH Action currently doesn't support current non-LCOV reporting format
# For now, still using Travis for unit test coverage reporting
# https://github.com/coverallsapp/github-action/issues/30
# - name: Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# Re-add git version control so we can run gitlint on itself.
- name: Re-add git version control to code
run: mv ._git .git
# Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations.
# PRs get squashed and get a proper commit message during merge.
- name: Gitlint check
run: ./run_tests.sh -g --debug
if: ${{ github.event_name != 'pull_request' }}
windows-checks:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- 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.
# 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@v4.2.0
with:
python-version: ${{ matrix.python-version }}
- name: "Upgrade pip on Python 3"
if: matrix.python-version == '3.10'
run: python -m pip install --upgrade pip
- name: Install requirements
run: |
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: gitlint --version
run: gitlint --version
- name: Tests (sanity)
run: tools\windows\run_tests.bat "gitlint-core\gitlint\tests\cli\test_cli.py::CLITests::test_lint"
- name: Tests (ignore cli\*)
run: pytest --ignore gitlint-core\gitlint\tests\cli -rw -s gitlint-core
- name: Tests (test_cli.py only - continue-on-error:true)
run: tools\windows\run_tests.bat "gitlint-core\gitlint\tests\cli\test_cli.py"
continue-on-error: true # Known to fail at this point
- name: Tests (all - continue-on-error:true)
run: tools\windows\run_tests.bat
continue-on-error: true # Known to fail at this point
- name: Integration tests (continue-on-error:true)
run: pytest -rw -s qa
continue-on-error: true # Known to fail at this point
- name: Code formatting (black)
run: black .
- name: PyLint
run: pylint gitlint-core\gitlint qa --rcfile=".pylintrc" -r n
# Re-add git version control so we can run gitlint on itself.
- name: Re-add git version control to code
run: Rename-Item ._git .git
# Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations.
# PRs get squashed and get a proper commit message during merge.
- name: Gitlint check
run: gitlint --debug
if: ${{ github.event_name != 'pull_request' }}

142
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,142 @@
name: Tests and Checks
# Only run CI on pushes to main and pull requests
# We don't run CI on other branches, but those should be merged into main via a PR anyways which will trigger CI before the merge.
on:
push:
branches:
- main
pull_request:
branches:
- main
concurrency:
group: ci-${{ github.ref }}-1
cancel-in-progress: true
jobs:
checks:
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.9]
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
steps:
- uses: actions/checkout@v3.3.0
with:
ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit
fetch-depth: 0 # checkout all history, needed for hatch versioning
- name: Setup python
uses: actions/setup-python@v4.5.0
with:
python-version: ${{ matrix.python-version }}
- name: Install pypa/build
run: python -m pip install build==0.10.0
- name: Install Hatch
run: python -m pip install hatch==1.6.3
- name: Unit Tests
run: hatch run test:unit-tests
- name: Code formatting (black)
run: hatch run test:format
- name: Code linting (ruff)
run: hatch run test:lint
- name: Install local gitlint for integration tests
run: |
hatch run qa:install-local
- name: Integration tests (default -> GITLINT_USE_SH_LIB=1)
run: |
hatch run qa:integration-tests
if: matrix.os != 'windows-latest'
- name: Integration tests (GITLINT_USE_SH_LIB=1)
run: |
hatch run qa:integration-tests
env:
GITLINT_USE_SH_LIB: 1
if: matrix.os != 'windows-latest'
- name: Integration tests (GITLINT_QA_USE_SH_LIB=0)
run: |
hatch run qa:integration-tests -k "not(test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit)" qa
env:
GITLINT_QA_USE_SH_LIB: 0
if: matrix.os != 'windows-latest'
- name: Integration tests (Windows)
run: |
hatch run qa:integration-tests -k "not (test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit or test_lint_staged_stdin or test_stdin_file or test_stdin_pipe_empty)" qa
if: matrix.os == 'windows-latest'
- name: Build test (gitlint)
run: |
python -m build
hatch clean
- name: Build test (gitlint-core)
run: |
python -m build
hatch clean
working-directory: ./gitlint-core
- name: Docs build (mkdocs)
run: hatch run docs:build
# Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations.
# PRs get squashed and get a proper commit message during merge.
- name: gitlint --debug
run: hatch run dev:gitlint --debug
continue-on-error: ${{ github.event_name == 'pull_request' }} # Don't enforce gitlint in PRs
- name: Code Coverage (coveralls)
uses: coverallsapp/github-action@master
with:
path-to-lcov: ".coverage.lcov"
github-token: ${{ secrets.GITHUB_TOKEN }}
git-commit: ${{ github.event.pull_request.head.sha }}
flag-name: gitlint-${{ matrix.os }}-${{ matrix.python-version }}
parallel: true
upload_coveralls:
needs: checks
runs-on: ubuntu-latest
steps:
- name: Upload coverage to coveralls
uses: coverallsapp/github-action@master
with:
path-to-lcov: ".coverage.lcov"
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
check: # This job does nothing and is only used for the branch protection
if: always() # Ref: https://github.com/marketplace/actions/alls-green#why
needs:
- upload_coveralls
- checks
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
# When on main, auto publish dev build
auto-publish-dev:
needs:
- check
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/publish-release.yml
secrets: inherit # pass all secrets (required to access secrets in a called workflow)
with:
pypi_target: "pypi.org"
repo_release_ref: "main"

14
.github/workflows/github-release.yml vendored Normal file
View file

@ -0,0 +1,14 @@
name: Github Release Publish
run-name: "Github Release Publish (tag=${{github.ref_name}})"
on:
release:
types: [published]
jobs:
publish-release:
uses: ./.github/workflows/publish-release.yml
secrets: inherit # pass all secrets (required to access secrets in a called workflow)
with:
pypi_target: "pypi.org"
repo_release_ref: ${{ github.ref_name }}

79
.github/workflows/publish-docker.yml vendored Normal file
View file

@ -0,0 +1,79 @@
name: Publish Docker
run-name: "Publish Docker (gitlint_version=${{ inputs.gitlint_version }})"
on:
workflow_call:
inputs:
gitlint_version:
description: "Gitlint version to build docker image for"
required: true
type: string
docker_image_tag:
description: "Docker image tag"
required: true
type: string
push_to_dockerhub:
description: "Push to dockerhub.com"
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
gitlint_version:
description: "Gitlint version to build docker image for"
type: string
docker_image_tag:
description: "Docker image tag"
required: true
type: choice
options:
- "latest_dev"
- "latest"
- "Use $gitlint_version"
default: "Use $gitlint_version"
push_to_dockerhub:
description: "Push to dockerhub.com"
required: false
type: boolean
default: false
jobs:
publish_docker:
runs-on: "ubuntu-latest"
steps:
- name: Determine docker tag
id: set_tag
run: |
if [[ "${{ inputs.docker_image_tag }}" == "Use $gitlint_version" ]]; then
echo "docker_image_tag=${{ inputs.gitlint_version }}" >> $GITHUB_OUTPUT
else
echo "docker_image_tag=${{ inputs.docker_image_tag }}" >> $GITHUB_OUTPUT
fi
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: jorisroovers
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build docker image
uses: docker/build-push-action@v4
with:
build-args: GITLINT_VERSION=${{ inputs.gitlint_version }}
tags: jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }}
- name: Test docker image
run: |
gitlint_version=$(docker run --ulimit nofile=1024 -v $(pwd):/repo jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }} --version)
[ "$gitlint_version" == "gitlint, version ${{ inputs.gitlint_version }}" ]
# This won't actually rebuild the docker image, but just push the previously built and cached image
- name: Push docker image
uses: docker/build-push-action@v4
with:
push: ${{ inputs.push_to_dockerhub }}
build-args: GITLINT_VERSION=${{ inputs.gitlint_version }}
tags: jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }}
if: inputs.push_to_dockerhub

176
.github/workflows/publish-release.yml vendored Normal file
View file

@ -0,0 +1,176 @@
name: Publish Release
run-name: "Publish Release (pypi_target=${{ inputs.pypi_target }}, repo_release_ref=${{ inputs.repo_release_ref }})"
on:
# Trigger release workflow from other workflows (e.g. release dev build as part of CI)
workflow_call:
inputs:
pypi_target:
description: "PyPI repository to publish to"
required: true
type: string
default: "test.pypi.org"
repo_release_ref:
description: "Gitlint git reference to publish release for"
type: string
default: "main"
# Manually trigger a release
workflow_dispatch:
inputs:
pypi_target:
description: "PyPI repository to publish to"
required: true
type: choice
options:
- "pypi.org"
- "test.pypi.org"
default: "test.pypi.org"
repo_release_ref:
description: "Gitlint git reference to publish release for"
type: string
default: "main"
jobs:
publish:
timeout-minutes: 15
runs-on: "ubuntu-latest"
outputs:
gitlint_version: ${{ steps.set_version.outputs.gitlint_version }}
steps:
- name: Setup python
uses: actions/setup-python@v4.5.0
with:
python-version: "3.11"
- name: Install pypa/build
run: python -m pip install build==0.10.0
- name: Install Hatch
run: python -m pip install hatch==1.6.3
- uses: actions/checkout@v3.3.0
with:
ref: ${{ inputs.repo_release_ref }}
fetch-depth: 0 # checkout all history, needed for hatch versioning
# Run hatch version once to avoid additional output ("Setting up build environment for missing dependencies")
# during the next step
- name: Hatch version
run: hatch version
# Hatch versioning is based on git (using hatch-vcs). If there is no explicit tag for the commit we're trying to
# publish, hatch versioning strings will have this format: 0.19.0.dev52+g9f7dc7d
# With the string after '+' being the 'g<short-sha>' of the commit.
#
# However, PyPI doesn't allow '+' in version numbers (no PEP440 local versions allowed on PyPI).
# To work around this, we override the version string by setting the SETUPTOOLS_SCM_PRETEND_VERSION env var
# to the version string without the '+' and everything after it.
# We do this by setting the `gitlint_version` step output here and re-using it later to
# set SETUPTOOLS_SCM_PRETEND_VERSION.
#
# We only actually publish such releases on the main branch to guarantee the dev numbering scheme remains
# unique.
# Note that when a tag *is* present (i.e. v0.19.0), hatch versioning will return the tag name (i.e. 0.19.0)
# and this step has no effect, ie. SETUPTOOLS_SCM_PRETEND_VERSION will be the same as `hatch version`.
- name: Set SETUPTOOLS_SCM_PRETEND_VERSION
id: set_version
run: |
echo "gitlint_version=$(hatch version | cut -d+ -f1)" >> $GITHUB_OUTPUT
- name: Build (gitlint-core)
run: python -m build
working-directory: ./gitlint-core
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.set_version.outputs.gitlint_version }}
- name: Build (gitlint)
run: python -m build
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.set_version.outputs.gitlint_version }}
- name: Publish gitlint-core (pypi.org)
run: hatch publish
working-directory: ./gitlint-core
env:
HATCH_INDEX_USER: ${{ secrets.PYPI_GITLINT_CORE_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.PYPI_GITLINT_CORE_PASSWORD }}
if: inputs.pypi_target == 'pypi.org'
- name: Publish gitlint (pypi.org)
run: hatch publish
env:
HATCH_INDEX_USER: ${{ secrets.PYPI_GITLINT_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.PYPI_GITLINT_PASSWORD }}
if: inputs.pypi_target == 'pypi.org'
- name: Publish gitlint-core (test.pypi.org)
run: hatch publish -r test
working-directory: ./gitlint-core
env:
HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_CORE_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_CORE_PASSWORD }}
if: inputs.pypi_target == 'test.pypi.org'
- name: Publish gitlint (test.pypi.org)
run: hatch publish -r test
env:
HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_PASSWORD }}
if: inputs.pypi_target == 'test.pypi.org'
# Wait for gitlint package to be available in PyPI for installation
wait-for-package:
needs:
- publish
runs-on: "ubuntu-latest"
steps:
- name: Install gitlint
uses: nick-fields/retry@v2.8.3
with:
timeout_minutes: 1
max_attempts: 10
command: |
python -m pip install gitlint==${{ needs.publish.outputs.gitlint_version }}
if: inputs.pypi_target == 'pypi.org'
- name: Install gitlint (test.pypi.org)
uses: nick-fields/retry@v2.8.3
with:
timeout_minutes: 1
max_attempts: 10
command: |
pip install --no-cache-dir -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple gitlint==${{ needs.publish.outputs.gitlint_version }}
if: inputs.pypi_target == 'test.pypi.org'
- name: gitlint --version
run: |
gitlint --version
[ "$(gitlint --version)" == "gitlint, version ${{ needs.publish.outputs.gitlint_version }}" ]
# Unfortunately, it's not because the newly published package installation worked once that replication
# has finished amongst all PyPI servers (subsequent installations might still fail). We sleep for 10 min here
# to increase the odds that replication has finished.
- name: Sleep
run: sleep 600
test-release:
needs:
- publish
- wait-for-package
uses: ./.github/workflows/test-release.yml
with:
gitlint_version: ${{ needs.publish.outputs.gitlint_version }}
pypi_source: ${{ inputs.pypi_target }}
repo_test_ref: ${{ inputs.repo_release_ref }}
publish-docker:
needs:
- publish
- test-release
uses: ./.github/workflows/publish-docker.yml
secrets: inherit # pass all secrets (required to access secrets in a called workflow)
with:
gitlint_version: ${{ needs.publish.outputs.gitlint_version }}
docker_image_tag: "latest_dev"
push_to_dockerhub: true

95
.github/workflows/test-release.yml vendored Normal file
View file

@ -0,0 +1,95 @@
name: Test Release
run-name: "Test Release (${{ inputs.gitlint_version }}, pypi_source=${{ inputs.pypi_source }}, repo_test_ref=${{ inputs.repo_test_ref }})"
on:
workflow_call:
inputs:
gitlint_version:
description: "Gitlint version to test"
required: true
default: "0.18.0"
type: string
pypi_source:
description: "PyPI repository to use"
required: true
type: string
repo_test_ref:
description: "Git reference to checkout for integration tests"
default: "main"
type: string
workflow_dispatch:
inputs:
gitlint_version:
description: "Gitlint version to test"
required: true
default: "0.18.0"
pypi_source:
description: "PyPI repository to use"
required: true
type: choice
options:
- "pypi.org"
- "test.pypi.org"
default: "pypi.org"
repo_test_ref:
description: "Git reference to checkout for integration tests"
default: "main"
jobs:
test-release:
timeout-minutes: 10
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.9]
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
steps:
- name: Setup python
uses: actions/setup-python@v4.5.0
with:
python-version: ${{ matrix.python-version }}
- name: Install Hatch
run: python -m pip install hatch==1.6.3
- name: Install gitlint
run: |
python -m pip install gitlint==${{ inputs.gitlint_version }}
if: inputs.pypi_source == 'pypi.org'
- name: Install gitlint (test.pypi.org)
run: |
pip install --no-cache-dir -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple gitlint==${{ inputs.gitlint_version }}
if: inputs.pypi_source == 'test.pypi.org'
- name: gitlint --version
run: |
gitlint --version
[ "$(gitlint --version)" == "gitlint, version ${{ inputs.gitlint_version }}" ]
- uses: actions/checkout@v3.3.0
with:
ref: ${{ inputs.repo_test_ref }}
- name: Integration tests (default -> GITLINT_USE_SH_LIB=1)
run: |
hatch run qa:integration-tests
if: matrix.os != 'windows-latest'
- name: Integration tests (GITLINT_USE_SH_LIB=1)
run: |
hatch run qa:integration-tests
env:
GITLINT_USE_SH_LIB: 1
if: matrix.os != 'windows-latest'
- name: Integration tests (GITLINT_QA_USE_SH_LIB=0)
run: |
hatch run qa:integration-tests -k "not(test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit)" qa
env:
GITLINT_QA_USE_SH_LIB: 0
if: matrix.os != 'windows-latest'
- name: Integration tests (Windows)
run: |
hatch run qa:integration-tests -k "not (test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit or test_lint_staged_stdin or test_stdin_file or test_stdin_pipe_empty)" qa
if: matrix.os == 'windows-latest'

9
.gitlint Normal file
View file

@ -0,0 +1,9 @@
[general]
# See https://jorisroovers.com/gitlint/configuration/#regex-style-search
regex-style-search=True
# Dependabot tends to generate lines that exceed the default 80 char limit.
[ignore-by-author-name]
regex=dependabot
ignore=all

View file

@ -1,48 +0,0 @@
# The format of this file isn't really documented; just use --generate-rcfile
[MASTER]
[Messages Control]
# C0111: Don't require docstrings on every method
# W0511: TODOs in code comments are fine.
# W0142: *args and **kwargs are fine.
# W0223: abstract methods don't need to be overwritten (i.e. when overwriting a Django REST serializer)
# W0622: Redefining id is fine.
# R0901: Too many ancestors (i.e. when subclassing test classes)
# R0801: Similar lines in files
# I0011: Informational: locally disabled pylint
# I0013: Informational: Ignoring entire file
disable=bad-option-value,C0111,W0511,W0142,W0622,W0223,W0212,R0901,R0801,I0011,I0013,anomalous-backslash-in-string,useless-object-inheritance,unnecessary-pass
[Format]
max-line-length=120
[Basic]
# Variable names can be 1 to 31 characters long, with lowercase and underscores
variable-rgx=[a-z_][a-z0-9_]{0,30}$
# Argument names can be 2 to 31 characters long, with lowercase and underscores
argument-rgx=[a-z_][a-z0-9_]{1,30}$
# Method names should be at least 3 characters long
# and be lower-cased with underscores
method-rgx=([a-z_][a-z0-9_]{2,50}|setUp|tearDown)$
# Allow 'id' as variable name everywhere
good-names=id,c,_
bad-names=__author__
# Ignore all variables that start with an underscore (e.g. unused _request variable in a view)
dummy-variables-rgx=_
[Design]
max-public-methods=100
min-public-methods=0
# Maximum number of attributes of a class
max-attributes=15
max-args=10
max-locals=20
[Typecheck]
# Allow the use of the Django 'objects' members
generated-members=sh.git

View file

@ -1,28 +1,80 @@
# Changelog #
# Changelog
This file documents notable changes introduced in gitlint releases.
# v0.20.0 (Unreleased)
# v0.19.1 (2023-03-10)
## Development
- Fix issue that prevented homebrew packages from being built ([#460](https://github.com/jorisroovers/gitlint/issues/460))
- Switch to using pypa/build in CI ([#463](https://github.com/jorisroovers/gitlint/issues/463)) - thanks @webknjaz
## v0.18.0 (2022-11-16) ##
# v0.19.0 (2023-03-07)
This release was primarily focussed on modernizing gitlint's build and test tooling (details: [#378](https://github.com/jorisroovers/gitlint/issues/378)).
## General
- Python 3.6 no longer supported ([EOL since 2021-12-23](https://endoflife.date/python)) ([#379](https://github.com/jorisroovers/gitlint/issues/379))
- This is the last release to support the [sh](https://amoffat.github.io/sh/) library (used under-the-hood to execute git commands) by setting `GITLINT_USE_SH_LIB=1`. This is already disabled by default since v0.18.0.
## Features
- Allow for a single commit in the `--commits` cmd-line param ([#412](https://github.com/jorisroovers/gitlint/issues/412)) - thanks [carlescufi](https://github.com/carlescufi)
- Gitlint now separates `FILE_ENCODING` (always UTF-8) from `TERMINAL_ENCODING` (terminal dependent), this should improve issues with unicode. Use `gitlint --debug` to inspect these values. ([#424](https://github.com/jorisroovers/gitlint/issues/424))
## Bugfixes
- `ignore-by-author-name` crashes without --staged ([#445](https://github.com/jorisroovers/gitlint/issues/445))
- Various documentation fixes ([#401](https://github.com/jorisroovers/gitlint/issues/401), [#433](https://github.com/jorisroovers/gitlint/issues/433)) - Thanks [scop](https://github.com/scop)
## Development
- Adopted [hatch](https://hatch.pypa.io/latest/) for project management ([#384](https://github.com/jorisroovers/gitlint/issues/384)).
This significantly improves the developer workflow, please read the updated [CONTRIBUTING](https://jorisroovers.com/gitlint/contributing/) page.
- Adopted [ruff](https://github.com/charliermarsh/ruff) for linting, replacing pylint ([#404](https://github.com/jorisroovers/gitlint/issues/404))
- Gitlint now publishes [dev builds on every commit to main](https://jorisroovers.github.io/gitlint/contributing/#dev-builds) ([#429](https://github.com/jorisroovers/gitlint/issues/429))
- Gitlint now publishes a [`latest_dev` docker image](https://hub.docker.com/r/jorisroovers/gitlint/tags?name=latest_dev) on every commit to main ([#451](https://github.com/jorisroovers/gitlint/issues/452)) ([#452](https://github.com/jorisroovers/gitlint/issues/451))
- Dependencies updated
- Many improvements to the [CI/CD worfklows](https://github.com/jorisroovers/gitlint/tree/main/.github/workflows)
- Fixed coveralls integration: [coveralls.io/github/jorisroovers/gitlint](https://coveralls.io/github/jorisroovers/gitlint)
- Improve unit test coverage ([#453](https://github.com/jorisroovers/gitlint/issues/453))
- Integration test fixes on windows ([#392](https://github.com/jorisroovers/gitlint/issues/392), [#397](https://github.com/jorisroovers/gitlint/issues/397))
- Devcontainer improvements ([#428](https://github.com/jorisroovers/gitlint/issues/428))
- Removal of Dockerfile.dev ([#390](https://github.com/jorisroovers/gitlint/issues/390))
- Fix most integration tests on Windows
- Fix Windows unit tests ([#383](https://github.com/jorisroovers/gitlint/issues/383))
- Introduce a gate/check GHA job ([#375](https://github.com/jorisroovers/gitlint/issues/375)) - Thanks [webknjaz](https://github.com/webknjaz)
- Thanks to [sigmavirus24](https://github.com/sigmavirus24) for continued overall help and support
# v0.18.0 (2022-11-16)
Contributors:
Special thanks to all contributors for this release - details inline!
## General
- 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))
## Features
- `--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:
## 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:
## 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:
## 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:
## Development
- Dependencies updated
- Moved to [black](https://github.com/psf/black) for formatting
- Fixed nasty CI issue ([#298](https://github.com/jorisroovers/gitlint/issues/298))
@ -32,63 +84,75 @@ Special thanks to all contributors for this release - details inline!
- 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) ##
# 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).
## General
- Gitlint is now split in 2 packages: `gitlint` and `gitlint-core`. This allows users to install gitlint without pinned dependencies (which is the default) ([#162](https://github.com/jorisroovers/gitlint/issues/162))
- Under-the-hood: dependencies updated
## v0.16.0 (2021-10-08) ##
# v0.16.0 (2021-10-08)
Contributors:
Special thanks to all contributors for this release, in particular [sigmavirus24](https://github.com/sigmavirus24), [l0b0](https://github.com/l0b0) and [rafaelbubach](https://github.com/rafaelbubach).
## General
- 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
- 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.
## Features
- `--commit <ref>` 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:
## Rules
- **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
## 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 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) ##
## Development
- Dependencies updated
- Test and github action improvements
# v0.15.1 (2021-04-16)
Contributors:
Special thanks to all contributors for this release, in particular [PW999](https://github.com/PW999), [gsemet](https://github.com/gsemet) and [Lorac](https://github.com/Lorac).
Bugfixes:
## Bugfixes
- Git commit message body with only new lines is not longer considered empty by `body-is-missing` ([#176](https://github.com/jorisroovers/gitlint/issues/176))
- Added compatibility with `git commit -s` for `contrib-requires-signed-off-by` rule ([#178](https://github.com/jorisroovers/gitlint/pull/178))
- Minor tweak to gitlint commit-hook output ([#173](https://github.com/jorisroovers/gitlint/pull/173))
- All dependencies have been upgraded to the latest available versions (`Click==7.1.2`, `arrow==1.0.3`, `sh==1.14.1`).
- Minor doc fixes
## v0.15.0 (2020-11-27) ##
# v0.15.0 (2020-11-27)
Contributors:
Special thanks to [BrunIF](https://github.com/BrunIF), [lukech](https://github.com/lukech), [Cielquan](https://github.com/Cielquan), [harens](https://github.com/harens) and [sigmavirus24](https://github.com/sigmavirus24).
**This release drops support for Python 2.7 and Python 3.5 ([both are EOL](https://endoflife.date/python)). Other than a few minor fixes, there are no functional differences from the 0.14.0 release.**
## General
Other call-outs:
- **This release drops support for Python 2.7 and Python 3.5 ([both are EOL](https://endoflife.date/python)). Other than a few minor fixes, there are no functional differences from the 0.14.0 release.**
- **Mac users**: Gitlint can now be installed using both homebrew (upgraded to latest) and macports. Special thanks to [@harens](https://github.com/harens) for maintaining these packages (best-effort).
- Bugfix: Gitlint now properly handles exceptions when using its built-in commit-msg hook ([#166](https://github.com/jorisroovers/gitlint/issues/166)).
## Bugfixes
- Gitlint now properly handles exceptions when using its built-in commit-msg hook ([#166](https://github.com/jorisroovers/gitlint/issues/166)).
## Development
- All dependencies have been upgraded to the latest available versions (`Click==7.1.2`, `arrow==0.17.0`, `sh==1.14.1`).
- Much under-the-hood refactoring as a result of dropping Python 2.7
## v0.14.0 (2020-10-24) ##
# v0.14.0 (2020-10-24)
Contributors:
Special thanks to all contributors for this release, in particular [mrshu](https://github.com/mrshu), [glasserc](https://github.com/glasserc), [strk](https://github.com/strk), [chgl](https://github.com/chgl), [melg8](https://github.com/melg8) and [sigmavirus24](https://github.com/sigmavirus24).
## General
- **IMPORTANT: Gitlint 0.14.x will be the last gitlint release to support Python 2.7 and Python 3.5, as [both are EOL](https://endoflife.date/python) which makes it difficult to keep supporting them.**
- Python 3.9 support
- **New Rule**: [title-min-length](http://jorisroovers.github.io/gitlint/rules/#t8-title-min-length) enforces a minimum length on titles (default: 5 chars) ([#138](https://github.com/jorisroovers/gitlint/issues/138))
- **New Rule**: [body-match-regex](http://jorisroovers.github.io/gitlint/rules/#b8-body-match-regex) allows users to enforce that the commit-msg body matches a given regex ([#130](https://github.com/jorisroovers/gitlint/issues/130))
- **New Rule**: [ignore-body-lines](http://jorisroovers.github.io/gitlint/rules/#i3-ignore-body-lines) allows users to
[ignore parts of a commit](http://jorisroovers.github.io/gitlint/gitlint/#ignoring-commits) by matching a regex against
the lines in a commit message body ([#126](https://github.com/jorisroovers/gitlint/issues/126))
- [Named Rules](http://jorisroovers.github.io/gitlint/#named-rules) allow users to have multiple instances of the same rule active at the same time. This is useful when you want to enforce the same rule multiple times but with different options ([#113](https://github.com/jorisroovers/gitlint/issues/113), [#66](https://github.com/jorisroovers/gitlint/issues/66))
- [User-defined Configuration Rules](http://jorisroovers.github.io/gitlint/user_defined_rules/#configuration-rules) allow users to dynamically change gitlint's configuration and/or the commit *before* any other rules are applied.
- The `commit-msg` hook has been re-written in Python (it contained a lot of Bash before), fixing a number of platform specific issues. Existing users will need to reinstall their hooks (`gitlint uninstall-hook; gitlint install-hook`) to make use of this.
@ -96,45 +160,75 @@ the lines in a commit message body ([#126](https://github.com/jorisroovers/gitli
- Users can now use `self.log.debug("my message")` for debugging purposes in their user-defined rules. Debug messages will show up when running `gitlint --debug`.
- **Breaking**: User-defined rule id's can no longer start with 'I', as those are reserved for [built-in gitlint ignore rules](http://jorisroovers.github.io/gitlint/rules/#i1-ignore-by-title).
- New `RegexOption` rule [option type for use in user-defined rules](http://jorisroovers.github.io/gitlint/user_defined_rules/#options). By using the `RegexOption`, regular expressions are pre-validated at gitlint startup and compiled only once which is much more efficient when linting multiple commits.
- Bugfixes:
- Improved UTF-8 fallback on Windows (ongoing - [#96](https://github.com/jorisroovers/gitlint/issues/96))
- Windows users can now use the 'edit' function of the `commit-msg` hook ([#94](https://github.com/jorisroovers/gitlint/issues/94))
- Doc update: Users should use `--ulimit nofile=1024` when invoking gitlint using Docker ([#129](https://github.com/jorisroovers/gitlint/issues/129))
- The `commit-msg` hook was broken in Ubuntu's gitlint package due to a python/python3 mismatch ([#127](https://github.com/jorisroovers/gitlint/issues/127))
- Better error message when no git username is set ([#149](https://github.com/jorisroovers/gitlint/issues/149))
- Options can now actually be set to `None` (from code) to make them optional.
- Ignore rules no longer have `"None"` as default regex, but an empty regex - effectively disabling them by default (as intended).
- Contrib Rules:
- Added 'ci' and 'build' to conventional commit types ([#135](https://github.com/jorisroovers/gitlint/issues/135))
- Under-the-hood: minor performance improvements (removed some unnecessary regex matching), test improvements, improved debug logging, CI runs on pull requests, PR request template.
## v0.13.1 (2020-02-26)
## Rules
- **New Rule**: [title-min-length](http://jorisroovers.github.io/gitlint/rules/#t8-title-min-length) enforces a minimum length on titles (default: 5 chars) ([#138](https://github.com/jorisroovers/gitlint/issues/138))
- **New Rule**: [body-match-regex](http://jorisroovers.github.io/gitlint/rules/#b8-body-match-regex) allows users to enforce that the commit-msg body matches a given regex ([#130](https://github.com/jorisroovers/gitlint/issues/130))
- **New Rule**: [ignore-body-lines](http://jorisroovers.github.io/gitlint/rules/#i3-ignore-body-lines) allows users to
[ignore parts of a commit](http://jorisroovers.github.io/gitlint/gitlint/#ignoring-commits) by matching a regex against
the lines in a commit message body ([#126](https://github.com/jorisroovers/gitlint/issues/126))
## Contrib Rules
- Added 'ci' and 'build' to conventional commit types ([#135](https://github.com/jorisroovers/gitlint/issues/135))
## Bugfixes
- Improved UTF-8 fallback on Windows (ongoing - [#96](https://github.com/jorisroovers/gitlint/issues/96))
- Windows users can now use the 'edit' function of the `commit-msg` hook ([#94](https://github.com/jorisroovers/gitlint/issues/94))
- Doc update: Users should use `--ulimit nofile=1024` when invoking gitlint using Docker ([#129](https://github.com/jorisroovers/gitlint/issues/129))
- The `commit-msg` hook was broken in Ubuntu's gitlint package due to a python/python3 mismatch ([#127](https://github.com/jorisroovers/gitlint/issues/127))
- Better error message when no git username is set ([#149](https://github.com/jorisroovers/gitlint/issues/149))
- Options can now actually be set to `None` (from code) to make them optional.
- Ignore rules no longer have `"None"` as default regex, but an empty regex - effectively disabling them by default (as intended).
## Development
- Minor performance improvements (removed some unnecessary regex matching),
- Test improvements,
- Improved debug logging,
- CI runs on pull requests
- PR request template
# v0.13.1 (2020-02-26)
## Bugfixes
- Patch to enable `--staged` flag for pre-commit.
- Minor doc updates ([#109](https://github.com/jorisroovers/gitlint/issues/109))
## v0.13.0 (2020-02-25)
# v0.13.0 (2020-02-25)
- **Behavior Change**: Revert Commits are now recognized and ignored by default ([#99](https://github.com/jorisroovers/gitlint/issues/99))
- `--staged` flag: gitlint can now detect meta-data (such as author details, changed files, etc) of staged/pre-commits. Useful when you use [gitlint's commit-msg hook](https://jorisroovers.github.io/gitlint/#using-gitlint-as-a-commit-msg-hook) or [precommit](https://jorisroovers.github.io/gitlint/#using-gitlint-through-pre-commit) ([#105](https://github.com/jorisroovers/gitlint/issues/105))
- New branch properties on `GitCommit` and `GitContext`, useful when writing your own user-defined rules: `commit.branches` and `commit.context.current_branch` ([#108](https://github.com/jorisroovers/gitlint/issues/108))
## General
- Python 3.8 support
- Python 3.4 no longer supported. Python 3.4 has [reached EOL](https://www.python.org/dev/peps/pep-0429/#id4) and an increasing
of gitlint's dependencies have dropped support which makes it hard to maintain.
- Improved Windows support: better unicode handling. [Issues remain](https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows) but the basic functionality works.
- Bugfixes:
- **Behavior Change**: Revert Commits are now recognized and ignored by default ([#99](https://github.com/jorisroovers/gitlint/issues/99))
## Features
- `--staged` flag: gitlint can now detect meta-data (such as author details, changed files, etc) of staged/pre-commits. Useful when you use [gitlint's commit-msg hook](https://jorisroovers.github.io/gitlint/#using-gitlint-as-a-commit-msg-hook) or [precommit](https://jorisroovers.github.io/gitlint/#using-gitlint-through-pre-commit) ([#105](https://github.com/jorisroovers/gitlint/issues/105))
- New branch properties on `GitCommit` and `GitContext`, useful when writing your own user-defined rules: `commit.branches` and `commit.context.current_branch` ([#108](https://github.com/jorisroovers/gitlint/issues/108))
## Bugfixes
- Gitlint no longer crashes when acting on empty repositories (this only occurred in specific circumstances).
- Changed files are now better detected in repos that only have a root commit
- Improved performance and memory (gitlint now caches git properties)
- Improved `--debug` output
- Improved documentation
- Under-the-hood: dependencies updated, unit and integration test improvements, migrated from TravisCI to Github Actions.
## v0.12.0 (2019-07-15) ##
## Development
- Dependencies updated
- Unit and integration test improvements
- Migrated from TravisCI to Github Actions.
# v0.12.0 (2019-07-15)
Contributors:
Special thanks to all contributors for this release, in particular [@rogalksi](https://github.com/rogalski) and [@byrney](https://github.com/byrney).
## General
- Python 3.3 no longer supported. Python 3.4 is likely to follow in a future release as it has [reached EOL](https://www.python.org/dev/peps/pep-0429/#id4) as well.
- PyPy 3.5 support
## Features
- [Contrib Rules](http://jorisroovers.github.io/gitlint/contrib_rules): community-contributed 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.
@ -143,40 +237,40 @@ Special thanks to all contributors for this release, in particular [@rogalksi](h
- If you're interested in adding new Contrib rules to gitlint, please start by reading the
[Contributing](http://jorisroovers.github.io/gitlint/contributing/) page. Thanks for considering!
- *Experimental (!)* Windows support: Basic functionality is working, but there are still caveats. For more details, please refer to [#20](https://github.com/jorisroovers/gitlint/issues/20) and the [open issues related to Windows](https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows).
- Python 3.3 no longer supported. Python 3.4 is likely to follow in a future release as it has [reached EOL](https://www.python.org/dev/peps/pep-0429/#id4) as well.
- PyPy 3.5 support
- Support for `--ignore-stdin` command-line flag to ignore any text send via stdin. ([#56](https://github.com/jorisroovers/gitlint/issues/56), [#89](https://github.com/jorisroovers/gitlint/issues/89))
- Bugfixes:
## Bugfixes
- [#68: Can't use install-hooks in with git worktree](https://github.com/jorisroovers/gitlint/issues/68)
- [#59: gitlint failed with configured commentchar](https://github.com/jorisroovers/gitlint/issues/59)
- Under-the-hood: dependencies updated, experimental Dockerfile, github issue template.
## v0.11.0 (2019-03-13) ##
## Development
- Dependencies updated
- Experimental Dockerfile
- Github issue template.
# v0.11.0 (2019-03-13)
## General
- Python 3.7 support
- Python 2.6 no longer supported
## Development
- Various dependency updates and under the hood fixes (see [#76](https://github.com/jorisroovers/gitlint/pull/76) for details).
Special thanks to @pbregener for his contributions related to python 3.7 support and test fixes.
## v0.10.0 (2018-04-15) ##
# v0.10.0 (2018-04-15)
The 0.10.0 release adds the ability to ignore commits based on their contents,
support for [pre-commit](https://pre-commit.com/), and important fix for running gitlint in CI environments
(such as Jenkins, Gitlab, etc).
Special thanks to [asottile](https://github.com/asottile), [bdrung](https://github.com/bdrung), [pbregener](https://github.com/pbregener), [torwald-sergesson](https://github.com/torwald-sergesson), [RykHawthorn](https://github.com/RykHawthorn), [SteffenKockel](https://github.com/SteffenKockel) and [tommyip](https://github.com/tommyip) for their contributions.
**Since it's becoming increasingly hard to support Python 2.6 and 3.3, we'd like to encourage our users to upgrade their
python version to 2.7 or 3.3+. Future versions of gitlint are likely to drop support for Python 2.6 and 3.3.**
## General
- **Since it's becoming increasingly hard to support Python 2.6 and 3.3, we'd like to encourage our users to upgrade their
python version to 2.7 or 3.3+. Future versions of gitlint are likely to drop support for Python 2.6 and 3.3.**
Full Changelog:
- **New Rule**: `ignore-by-title` allows users to
[ignore certain commits](http://jorisroovers.github.io/gitlint/#ignoring-commits) by matching a regex against
a commit message title. ([#54](https://github.com/jorisroovers/gitlint/issues/54), [#57](https://github.com/jorisroovers/gitlint/issues/57)).
- **New Rule**: `ignore-by-body` allows users to
[ignore certain commits](http://jorisroovers.github.io/gitlint/#ignoring-commits) by matching a regex against
a line in a commit message body.
## Features
- Gitlint now supports [pre-commit.com](https://pre-commit.com).
[Details in our documentation](http://jorisroovers.github.io/gitlint/#using-gitlint-through-pre-commit)
([#62](https://github.com/jorisroovers/gitlint/issues/62)).
@ -186,18 +280,26 @@ a line in a commit message body.
- Gitlint can now be installed on MacOS by brew via the [homebrew-devops](https://github.com/rockyluke/homebrew-devops) tap. To get the latest version of gitlint, always use pip for installation.
- If all goes well,
[gitlint will also be available as a package in the Ubuntu 18.04 repositories](https://launchpad.net/ubuntu/+source/gitlint).
- Bugfixes:
- We fixed a nasty and recurring issue with running gitlint in CI. Hopefully that's the end of it :-) ([#40](https://github.com/jorisroovers/gitlint/issues/40)).
- Fix for custom git comment characters ([#48](https://github.com/jorisroovers/gitlint/issues/48)).
## v0.9.0 (2017-12-03) ##
## Rules
- **New Rule**: `ignore-by-title` allows users to
[ignore certain commits](http://jorisroovers.github.io/gitlint/#ignoring-commits) by matching a regex against
a commit message title. ([#54](https://github.com/jorisroovers/gitlint/issues/54), [#57](https://github.com/jorisroovers/gitlint/issues/57)).
- **New Rule**: `ignore-by-body` allows users to
[ignore certain commits](http://jorisroovers.github.io/gitlint/#ignoring-commits) by matching a regex against
a line in a commit message body.
## Bugfixes
- We fixed a nasty and recurring issue with running gitlint in CI. Hopefully that's the end of it :-) ([#40](https://github.com/jorisroovers/gitlint/issues/40)).
- Fix for custom git comment characters ([#48](https://github.com/jorisroovers/gitlint/issues/48)).
# v0.9.0 (2017-12-03)
The 0.9.0 release adds a new default `author-valid-email` rule, important bugfixes and special case handling.
Special thanks to [joshholl](https://github.com/joshholl), [ron8mcr](https://github.com/ron8mcr),
[omarkohl](https://github.com/omarkohl), [domo141](https://github.com/domo141), [nud](https://github.com/nud)
and [AlexMooney](https://github.com/AlexMooney) for their contributions.
- New Rule: `author-valid-email` enforces a valid author email address. Details can be found in the
[Rules section of the documentation](http://jorisroovers.github.io/gitlint/rules/#m1-author-valid-email).
## General
- **Breaking change**: The `--commits` commandline flag now strictly follows the refspec format as interpreted
by the [`git rev-list <refspec>`](https://git-scm.com/docs/git-rev-list) command. This means
that linting a single commit using `gitlint --commits <ref>` won't work anymore. Instead, for single commits,
@ -212,68 +314,89 @@ and [AlexMooney](https://github.com/AlexMooney) for their contributions.
- **Behavior Change**: Gitlint will now by default
[ignore squash and fixup commits](http://jorisroovers.github.io/gitlint/#merge-fixup-and-squash-commits)
(fix for [#33: fixup messages should not trigger a gitlint violation](https://github.com/jorisroovers/gitlint/issues/33))
## Features
- Support for custom comment characters ([#34](https://github.com/jorisroovers/gitlint/issues/34))
- Support for [`git commit --cleanup=scissors`](https://git-scm.com/docs/git-commit#git-commit---cleanupltmodegt)
([#34](https://github.com/jorisroovers/gitlint/issues/34))
- Bugfix: [#37: Prevent Commas in text fields from breaking git log printing](https://github.com/jorisroovers/gitlint/issues/37)
## Rules
- New Rule: `author-valid-email` enforces a valid author email address. Details can be found in the
[Rules section of the documentation](http://jorisroovers.github.io/gitlint/rules/#m1-author-valid-email).
## Bugfixes
- [#37: Prevent Commas in text fields from breaking git log printing](https://github.com/jorisroovers/gitlint/issues/37)
## Development
- Debug output improvements
## v0.8.2 (2017-04-25) ##
# v0.8.2 (2017-04-25)
The 0.8.2 release brings minor improvements, bugfixes and some under-the-hood changes. Special thanks to
[tommyip](https://github.com/tommyip) for his contributions.
## Features
- `--extra-path` now also accepts a file path (in the past only directory paths where accepted).
Thanks to [tommyip](https://github.com/tommyip) for implementing this!
- gitlint will now show more information when using the `--debug` flag. This is initial work and will continue to
be improved upon in later releases.
- Bugfixes:
## Bugfixes
- [#24: --commits doesn't take commit specific config into account](https://github.com/jorisroovers/gitlint/issues/24)
- [#27: --commits returns the wrong exit code](https://github.com/jorisroovers/gitlint/issues/27)
- Development: better unit and integration test coverage for `--commits`
## Development
- Better unit and integration test coverage for `--commits`
## v0.8.1 (2017-03-16) ##
# v0.8.1 (2017-03-16)
The 0.8.1 release brings minor tweaks and some experimental features. Special thanks to
[tommyip](https://github.com/tommyip) for his contributions.
## General
- Experimental: Python 3.6 support
- Improved Windows error messaging: gitlint will now show a more descriptive error message when ran on windows.
See [#20](https://github.com/jorisroovers/gitlint/issues/20) for details on the lack of Windows support.
## Features
- Experimental: Linting a range of commits.
[Documentation](http://jorisroovers.github.io/gitlint/#linting-a-range-of-commits).
Known Caveats: [#23](https://github.com/jorisroovers/gitlint/issues/23),
[#24](https://github.com/jorisroovers/gitlint/issues/24).
Closes [#14](https://github.com/jorisroovers/gitlint/issues/14). Thanks to [tommyip](https://github.com/tommyip)
for implementing this!
- Experimental: Python 3.6 support
- Improved Windows error messaging: gitlint will now show a more descriptive error message when ran on windows.
See [#20](https://github.com/jorisroovers/gitlint/issues/20) for details on the lack of Windows support.
## v0.8.0 (2016-12-30) ##
# v0.8.0 (2016-12-30)
The 0.8.0 release is a significant release that has been in the works for a long time. Special thanks to
[Claymore](https://github.com/Claymore), [gernd](https://github.com/gernd) and
[ZhangYaxu](https://github.com/ZhangYaxu) for submitting bug reports and pull requests.
## General
- Full unicode support: you can now lint messages in any language! This fixes
[#16](https://github.com/jorisroovers/gitlint/issues/16) and [#18](https://github.com/jorisroovers/gitlint/pull/18).
- Pypy2 support!
- Various documentation improvements
## Features
- User-defined rules: you can now
[define your own custom rules](http://jorisroovers.github.io/gitlint/user_defined_rules/)
if you want to extend gitlint's functionality.
- Pypy2 support!
- Debug output improvements: Gitlint will now print your active configuration when using `--debug`
- The `general.target` option can now also be set via `-c` flags or a `.gitlint` file
- Bugfixes:
- Various important fixes related to configuration precedence
- [#17: Body MinLength is not working properly](https://github.com/jorisroovers/gitlint/issues/17).
**Behavior Change**: Gitlint now always applies this rule, even if the body has just a single line of content.
Also, gitlint now counts the body-length for the entire body, not just the length of the first line.
- Various documentation improvements
- Development:
- Pylint compliance for all supported python versions
- Updated dependencies to latest versions
- Various `run_tests.sh` improvements for developer convenience
## v0.7.1 (2016-06-18) ##
Bugfixes:
## Bugfixes
- Various important fixes related to configuration precedence
- [#17: Body MinLength is not working properly](https://github.com/jorisroovers/gitlint/issues/17).
**Behavior Change**: Gitlint now always applies this rule, even if the body has just a single line of content.
Also, gitlint now counts the body-length for the entire body, not just the length of the first line.
## Development
- Pylint compliance for all supported python versions
- Updated dependencies to latest versions
- Various `run_tests.sh` improvements for developer convenience
# v0.7.1 (2016-06-18)
## Bugfixes
- **Behavior Change**: gitlint no longer prints the file path by default when using a `.gitlint` file. The path
will still be printed when using the new `--debug` flag. Special thanks to [Slipcon](https://github.com/slipcon)
@ -283,53 +406,68 @@ for submitting this.
- Gitlint is now better at parsing commit messages cross-platform by taking platform specific line endings into account
- Minor documentation improvements
## v0.7.0 (2016-04-20) ##
# v0.7.0 (2016-04-20)
This release contains mostly bugfix and internal code improvements. Special thanks to
[William Turell](https://github.com/wturrell) and [Joe Grund](https://github.com/jgrund) for bug reports and pull
requests.
- commit-msg hooks improvements: The new commit-msg hook now allows you to edit your message if it contains violations,
prints the commit message on aborting and is more compatible with GUI-based git clients such as SourceTree.
*You will need to uninstall and reinstall the commit-msg hook for these latest features*.
## General
- Python 2.6 support
- **Behavior change**: merge commits are now ignored by default. The rationale is that the original commits
should already be linted and that many merge commits don't pass gitlint checks by default
(e.g. exceeding title length or empty body is very common). This behavior can be overwritten by setting the
general option `ignore-merge-commit=false`.
- Bugfixes and enhancements:
- [#7: Hook compatibility with SourceTree](https://github.com/jorisroovers/gitlint/issues/7)
- [#8: Illegal option -e](https://github.com/jorisroovers/gitlint/issues/8)
- [#9: print full commit msg to stdout if aborted](https://github.com/jorisroovers/gitlint/issues/9)
- [#11 merge commit titles exceeding the max title length by default](https://github.com/jorisroovers/gitlint/issues/11)
- Better error handling of invalid general options
- Development: internal refactoring to extract more info from git. This will allow for more complex rules in the future.
- Development: initial set of integration tests. Test gitlint end-to-end after it is installed.
- Development: pylint compliance for python 2.7
## v0.6.1 (2015-11-22) ##
## Features
- commit-msg hooks improvements: The new commit-msg hook now allows you to edit your message if it contains violations,
prints the commit message on aborting and is more compatible with GUI-based git clients such as SourceTree.
*You will need to uninstall and reinstall the commit-msg hook for these latest features*.
- Fix: `install-hook` and `generate-config` commands not working when gitlint is installed from pypi.
## Bugfixes
- [#7: Hook compatibility with SourceTree](https://github.com/jorisroovers/gitlint/issues/7)
- [#8: Illegal option -e](https://github.com/jorisroovers/gitlint/issues/8)
- [#9: print full commit msg to stdout if aborted](https://github.com/jorisroovers/gitlint/issues/9)
- [#11 merge commit titles exceeding the max title length by default](https://github.com/jorisroovers/gitlint/issues/11)
- Better error handling of invalid general options
## v0.6.0 (2015-11-22) ##
## Development
- internal refactoring to extract more info from git. This will allow for more complex rules in the future.
- initial set of integration tests. Test gitlint end-to-end after it is installed.
- pylint compliance for python 2.7
# v0.6.1 (2015-11-22)
## Bugfixes
- `install-hook` and `generate-config` commands not working when gitlint is installed from pypi.
# v0.6.0 (2015-11-22)
## General
- Python 3 (3.3+) support!
- All documentation is now hosted on [http://jorisroovers.github.io/gitlint/]()
- New `generate-config` command generates a sample gitlint config file
- New `--target` flag allows users to lint different directories than the current working directory
- **Breaking change**: exit code behavior has changed. More details in the
[Exit codes section of the documentation](http://jorisroovers.github.io/gitlint/#exit-codes).
- **Breaking change**: `--install-hook` and `--uninstall-hook` have been renamed to `install-hook` and
`uninstall-hook` respectively to better express that they are commands instead of options.
## Features
- New `generate-config` command generates a sample gitlint config file
- New `--target` flag allows users to lint different directories than the current working directory
- Better error handling when gitlint is executed in a directory that is not a git repository or
when git is not installed.
- The git commit message hook now uses pretty colored output
- Fix: `--config` option no longer accepts directories as value
- Development: unit tests are now ran using py.test
## v0.5.0 (2015-10-04) ##
## Bugfixes
- `--config` option no longer accepts directories as value
## Development
- Unit tests are now ran using py.test
# v0.5.0 (2015-10-04)
## Features
- New Rule: `title-match-regex`. Details can be found in the
[Rules section of the documentation](http://jorisroovers.github.io/gitlint/rules/).
- Uninstall previously installed gitlint git commit hooks using: `gitlint --uninstall-hook`
- Ignore rules on a per commit basis by adding e.g.: `gitlint-ignore: T1, body-hard-tab` to your git commit message.
Use `gitlint-ignore: all` to disable gitlint all together for a specific commit.
@ -338,38 +476,66 @@ requests.
- Violations are now sorted by line number first and then by rule id (previously the order of violations on the
same line was arbitrary).
## v0.4.1 (2015-09-19) ##
## Rules
- New Rule: `title-match-regex`. Details can be found in the
[Rules section of the documentation](http://jorisroovers.github.io/gitlint/rules/).
- Internal fix: added missing comma to setup.py which prevented pypi upload
# v0.4.1 (2015-09-19)
## v0.4.0 (2015-09-19) ##
## Bugfixes
- Added missing comma to setup.py which prevented pypi upload
# v0.4.0 (2015-09-19)
## General
- gitlint is now also released as a [python wheel](http://pythonwheels.com/) on pypi.
## Features
- The git `commit-msg` hook now allows you to keep or discard the commit when it fails gitlint validation
## Rules
- New rules: `body-is-missing`, `body-min-length`, `title-leading-whitespace`,
`body-changed-file-mention`. Details can be found in the
[Rules section of the documentation](http://jorisroovers.github.io/gitlint/rules/).
- The git `commit-msg` hook now allows you to keep or discard the commit when it fails gitlint validation
- gitlint is now also released as a [python wheel](http://pythonwheels.com/) on pypi.
## Development
- Internal: rule classes now have access to a gitcontext containing body the commit message and the files changed in the
last commit.
## v0.3.0 (2015-09-11) ##
- `title-must-not-contain-word` now has a `words` option that can be used to specify which words should not
occur in the title
# v0.3.0 (2015-09-11)
## Features
- gitlint violations are now printed to the stderr instead of stdout
- Various minor bugfixes
- gitlint now ignores commented out lines (i.e. starting with #) in your commit messages
- Experimental: git commit-msg hook support
## Rules
- `title-must-not-contain-word` now has a `words` option that can be used to specify which words should not
occur in the title
## Bugfixes
- Various minor bugfixes
## Development
- Under-the-hood: better test coverage :-)
## v0.2.0 (2015-09-10) ##
- Rules can now have their behavior configured through options.
For example, the `title-max-length` rule now has a `line-length` option.
- Under-the-hood: The codebase now has a basic level of unit test coverage, increasing overall quality assurance
## v0.1.1 (2015-09-08) ##
- Bugfix: added missing `sh` dependency
# v0.2.0 (2015-09-10)
## v0.1.0 (2015-09-08) ##
## Features
- Rules can now have their behavior configured through options.
For example, the `title-max-length` rule now has a `line-length` option.
## Development
- The codebase now has a basic level of unit test coverage, increasing overall quality assurance
# v0.1.1 (2015-09-08)
## Bugfixes
- Added missing `sh` dependency
# v0.1.0 (2015-09-08)
## General
- Initial gitlint release
- Initial set of rules: title-max-length, title-trailing-whitespace, title-trailing-punctuation , title-hard-tab,
title-must-not-contain-word, body-max-line-length, body-trailing-whitespace, body-hard-tab

View file

@ -1,5 +1,3 @@
# User-facing Dockerfile. For development, see Dockerfile.dev and ./run_tests.sh -h
# To lint your current working directory:
# docker run --ulimit nofile=1024 -v $(pwd):/repo jorisroovers/gitlint
@ -9,7 +7,7 @@
# NOTE: --ulimit is required to work around a limitation in Docker
# Details: https://github.com/jorisroovers/gitlint/issues/129
FROM python:3.11.0-alpine
FROM python:3.11.2-alpine
ARG GITLINT_VERSION
RUN apk add git

View file

@ -1,17 +0,0 @@
# Note: development using the local Dockerfile is still work-in-progress
# Getting started: http://jorisroovers.github.io/gitlint/contributing/
ARG python_version_dotted
FROM python:${python_version_dotted}-stretch
RUN apt-get update
# software-properties-common contains 'add-apt-repository'
RUN apt-get install -y git silversearcher-ag jq curl
ADD . /gitlint
WORKDIR /gitlint
RUN pip install --ignore-requires-python -r requirements.txt
RUN pip install --ignore-requires-python -r test-requirements.txt
CMD ["/bin/bash"]

View file

@ -1,7 +0,0 @@
include README.md
include LICENSE
exclude Vagrantfile
exclude *.yml *.sh *.txt
recursive-exclude examples *
recursive-exclude gitlint-core *
recursive-exclude qa *

View file

@ -1,15 +1,16 @@
# gitlint: [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) #
[![Tests](https://github.com/jorisroovers/gitlint/workflows/Tests%20and%20Checks/badge.svg)](https://github.com/jorisroovers/gitlint/actions?query=workflow%3A%22Tests+and+Checks%22)
[![Coverage Status](https://coveralls.io/repos/github/jorisroovers/gitlint/badge.svg?branch=fix-coveralls)](https://coveralls.io/github/jorisroovers/gitlint?branch=fix-coveralls)
[![PyPi Package](https://img.shields.io/pypi/v/gitlint.png)](https://pypi.python.org/pypi/gitlint)
![Supported Python Versions](https://img.shields.io/pypi/pyversions/gitlint.svg)
Git commit message linter written in python (for Linux and Mac, experimental on Windows), checks your commit messages for style.
Git commit message linter written in python, checks your commit messages for style.
**See [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) for full documentation.**
<a href="http://jorisroovers.github.io/gitlint/" target="_blank">
<img src="docs/images/readme-gitlint.png" />
<img src="https://raw.githubusercontent.com/jorisroovers/gitlint/main/docs/images/readme-gitlint.png" />
</a>
## Contributing ##

View file

@ -1 +0,0 @@
mkdocs==1.4.1

View file

@ -3,13 +3,14 @@
We'd love for you to contribute to gitlint. Thanks for your interest!
The [source-code and issue tracker](https://github.com/jorisroovers/gitlint) are hosted on Github.
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 project plan on github projects](https://github.com/users/jorisroovers/projects/1/), but
that's open to a lot of change and input.
!!! note
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 project plan on github projects](https://github.com/users/jorisroovers/projects/1/), but
that's open to a lot of change and input.
## Guidelines
## Overall Guidelines
When contributing code, please consider all the parts that are typically required:
@ -26,28 +27,46 @@ can make it as part of a release. **Gitlint commits and pull requests are gated
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
It's 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
to make it worthwhile or when there's a critical fix for a bug that fundamentally breaks gitlint. While the amount
of overhead of doing a release isn't huge, it's also not zero. In practice this means that it might take weeks
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.
## Releases
Gitlint releases typically go out when there's either enough new features and fixes
to make it worthwhile or when there's a critical fix for a bug that fundamentally breaks gitlint.
## Local setup
While the amount of overhead of doing a release isn't huge, it's also not zero. In practice this means that it might
take weeks 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.
To install gitlint for local development:
### Dev Builds
While final releases are usually months apart, we do dev builds on every commit to `main`:
- **gitlint**: [https://pypi.org/project/gitlint/#history](https://pypi.org/project/gitlint/#history)
- **gitlint-core**: [https://pypi.org/project/gitlint-core/#history](https://pypi.org/project/gitlint-core/#history)
It usually takes about 5 min after merging a PR to `main` for new dev builds to show up. Note that the installation
of a recently published version can still fail for a few minutes after a new version shows up on PyPI while the package
is replicated to all download mirrors.
To install a dev build of gitlint:
```sh
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt -r test-requirements.txt -r doc-requirements.txt
python setup.py develop
# Find latest dev build on https://pypi.org/project/gitlint/#history
pip install gitlint=="0.19.0.dev68"
```
## Github Devcontainer
## Environment setup
### Local setup
Gitlint uses [hatch](https://hatch.pypa.io/latest/) for project management.
You do not need to setup a `virtualenv`, hatch will take care of that for you.
```sh
pip install hatch
```
### Github Devcontainer
We provide a devcontainer on github to make it easier to get started with gitlint development using VSCode.
@ -59,12 +78,6 @@ To start one, click the plus button under the *Code* dropdown on
![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:
@ -83,27 +96,43 @@ asdf list python
## Running tests
```sh
./run_tests.sh # run unit tests and print test coverage
./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 --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, format and gitlint checks
# Gitlint
hatch run dev:gitlint # run the local source copy of gitlint
hatch run dev:gitlint --version # This is just the gitlint binary, any flag will work
hatch run dev:gitlint --debug
# Unit tests
hatch run test:unit-tests # run unit tests
hatch run test:unit-tests gitlint-core/gitlint/tests/rules/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test
hatch run test:unit-tests -k test_body_missing_merge_commit # Run a specific tests using a pytest keyword expression
hatch run test:unit-tests-no-cov # run unit tests without test coverage
# Integration tests
hatch run qa:install-local # One-time install: install the local gitlint source copy for integration testing
hatch run qa:integration-tests # Run integration tests
# Formatting check (black)
hatch run test:format # Run formatting checks
# Linting (ruff)
hatch run test:lint # Run Ruff
# Project stats
hatch run test:stats
```
## Formatting
## Autoformatting and autofixing
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
hatch run test:autoformat # format all python code
hatch run test:autoformat gitlint-core/gitlint/lint.py # format a specific file
```
We use [ruff](https://github.com/charliermarsh/ruff) for linting, it can autofix many of the issue it finds
(although not always perfect).
```sh
hatch run test:autofix # Attempt to fix linting issues
```
## Documentation
@ -111,8 +140,7 @@ We use [mkdocs](https://www.mkdocs.org/) for generating our documentation from m
To use it:
```sh
pip install -r doc-requirements.txt # install doc requirements
mkdocs serve
hatch run docs:serve
```
Then access the documentation website on [http://localhost:8000]().
@ -133,16 +161,17 @@ to split gitlint in 2 packages.
![Gitlint package structure](images/gitlint-packages.png)
### Packaging description
To see the package description in HTML format
To build the packages locally:
```sh
pip install docutils
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
python setup.py --long-description | rst2html.py > output.html
```
# gitlint
hatch build
hatch clean # cleanup
# gitlint-core
cd gitlint-core
hatch build
hatch clean # cleanup
```
## Tools
We keep a small set of scripts in the `tools/` directory:

View file

@ -7,7 +7,7 @@ Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or
<script type="text/javascript" src="https://asciinema.org/a/30477.js" id="asciicast-30477" async></script>
!!! note
**Gitlint support for Windows is experimental**, and [there are some known issues](https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows).
**Gitlint works on Windows**, but [there are some known issues](https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows).
Also, gitlint is not the only git commit message linter out there, if you are looking for an alternative written in a different language,
have a look at [fit-commit](https://github.com/m1foley/fit-commit) (Ruby),
@ -15,7 +15,7 @@ Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or
!!! important
**Gitlint no longer supports Python 2.7 and Python 3.5 as they [have reached End-Of-Life](https://endoflife.date/python). The last gitlint version to support Python 2.7 and Python 3.5 is `0.14.0` (released on October 24th, 2020).**
**Gitlint requires Python 3.7 (or above). For Python 2.7 and Python 3.5 use `gitlint==0.14.0` (released 2020-10-24), for Python 3.6 `gitlint==0.18.0` (released 2022-11-16).**
## Features
- **Commit message hook**: [Auto-trigger validations against new commit message right when you're committing](#using-gitlint-as-a-commit-msg-hook). Also [works with pre-commit](#using-gitlint-through-pre-commit).
@ -30,7 +30,8 @@ useful throughout the years.
- **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,
python code standards (pep8, pylint), good documentation, widely used, proven track record.
python code standards ([black](https://github.com/psf/black), [ruff](https://github.com/charliermarsh/ruff)),
good documentation, widely used, proven track record.
## Getting Started
### Installation
@ -271,7 +272,7 @@ 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
rev: # insert ref, e.g. v0.18.0
hooks:
- id: gitlint
- id: gitlint-ci
@ -317,12 +318,14 @@ 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"
gitlint --commits "origin/main..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
# You can also lint a single commit with --commits:
gitling --commits 019cf40,
```
The `--commits` flag takes a **single** refspec argument or commit range. Basically, any range that is understood
@ -331,6 +334,7 @@ by [git rev-list](https://git-scm.com/docs/git-rev-list) as a single argument wi
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.
`--commits` also accepts a single commit SHA with a trailing comma.
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.

View file

@ -1 +0,0 @@
../LICENSE

22
gitlint-core/LICENSE Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Joris Roovers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,3 +0,0 @@
include README.md
include LICENSE
recursive-exclude gitlint/tests *

View file

@ -1 +0,0 @@
../README.md

26
gitlint-core/README.md Normal file
View file

@ -0,0 +1,26 @@
# Gitlint-core
# gitlint: [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) #
[![Tests](https://github.com/jorisroovers/gitlint/workflows/Tests%20and%20Checks/badge.svg)](https://github.com/jorisroovers/gitlint/actions?query=workflow%3A%22Tests+and+Checks%22)
[![Coverage Status](https://coveralls.io/repos/github/jorisroovers/gitlint/badge.svg?branch=fix-coveralls)](https://coveralls.io/github/jorisroovers/gitlint?branch=fix-coveralls)
[![PyPi Package](https://img.shields.io/pypi/v/gitlint.png)](https://pypi.python.org/pypi/gitlint)
![Supported Python Versions](https://img.shields.io/pypi/pyversions/gitlint.svg)
Git commit message linter written in python, checks your commit messages for style.
**See [jorisroovers.github.io/gitlint](http://jorisroovers.github.io/gitlint/) for full documentation.**
<a href="http://jorisroovers.github.io/gitlint/" target="_blank">
<img src="https://raw.githubusercontent.com/jorisroovers/gitlint/main/docs/images/readme-gitlint.png" />
</a>
## Contributing ##
All contributions are welcome and very much appreciated!
**I'm [looking for contributors](https://github.com/jorisroovers/gitlint/issues/134) that are interested in taking a more active co-maintainer role as it's becoming increasingly difficult for me to find time to maintain gitlint. Please leave a comment in [#134](https://github.com/jorisroovers/gitlint/issues/134) if you're interested!**
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 project plan on Github Projects](https://github.com/users/jorisroovers/projects/1/views/1).

View file

@ -1 +1,8 @@
__version__ = "0.19.0dev"
import sys
if sys.version_info >= (3, 8):
from importlib import metadata # pragma: nocover
else:
import importlib_metadata as metadata # pragma: nocover
__version__ = metadata.version("gitlint-core")

View file

@ -13,7 +13,7 @@ class PropertyCache:
return self._cache[cache_key]
def cache(original_func=None, cachekey=None): # pylint: disable=unused-argument
def cache(original_func=None, cachekey=None):
"""Cache decorator. Caches function return values.
Requires the parent class to extend and initialize PropertyCache.
Usage:

View file

@ -1,22 +1,22 @@
# pylint: disable=bad-option-value,wrong-import-position
# We need to disable the import position checks because of the windows check that we need to do below
import copy
import logging
import os
import platform
import stat
import sys
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.config import LintConfigBuilder, LintConfigError, LintConfigGenerator
from gitlint.deprecation import DEPRECATED_LOG_FORMAT
from gitlint.deprecation import LOG as DEPRECATED_LOG
from gitlint.exception import GitlintError
from gitlint.git import GitContext, GitContextError, git_version
from gitlint.lint import GitLinter
from gitlint.shell import shell
from gitlint.utils import LOG_FORMAT
from gitlint.exception import GitlintError
# Error codes
GITLINT_SUCCESS = 0
@ -40,8 +40,6 @@ LOG = logging.getLogger("gitlint.cli")
class GitLintUsageError(GitlintError):
"""Exception indicating there is an issue with how gitlint is used."""
pass
def setup_logging():
"""Setup gitlint logging"""
@ -49,7 +47,7 @@ def setup_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)
root_log.setLevel(logging.WARN)
handler = logging.StreamHandler()
formatter = logging.Formatter(LOG_FORMAT)
handler.setFormatter(formatter)
@ -69,10 +67,11 @@ def log_system_info():
LOG.debug("Git version: %s", git_version())
LOG.debug("Gitlint version: %s", gitlint.__version__)
LOG.debug("GITLINT_USE_SH_LIB: %s", os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]"))
LOG.debug("DEFAULT_ENCODING: %s", gitlint.utils.DEFAULT_ENCODING)
LOG.debug("TERMINAL_ENCODING: %s", gitlint.utils.TERMINAL_ENCODING)
LOG.debug("FILE_ENCODING: %s", gitlint.utils.FILE_ENCODING)
def build_config( # pylint: disable=too-many-arguments
def build_config(
target,
config_path,
c,
@ -172,11 +171,9 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec):
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( # pylint: disable=unnecessary-lambda-assignment
message, lint_config.target
)
)
def from_commit_msg(message):
return GitContext.from_staged_commit(message, lint_config.target)
# Order of precedence:
# 1. Any data specified via --msg-filename
@ -208,7 +205,7 @@ def build_git_context(lint_config, msg_filename, commit_hash, refspec):
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(",")]
commit_hashes = [hash.strip() for hash in refspec.split(",") if hash]
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)
@ -247,43 +244,43 @@ class ContextObj:
# fmt: off
@click.group(invoke_without_command=True, context_settings={'max_content_width': 120},
@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',
@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', envvar='GITLINT_CONFIG',
@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,
@click.option("-c", multiple=True,
help="Config flags in format <rule>.<option>=<value> (e.g.: -c T1.line-length=80). " +
"Flag can be used multiple times to set multiple config values.") # pylint: disable=bad-continuation
@click.option('--commit', envvar='GITLINT_COMMIT', default=None, help="Hash (SHA) of specific commit to lint.")
@click.option('--commits', envvar='GITLINT_COMMITS', default=None,
"Flag can be used multiple times to set multiple config values.")
@click.option("--commit", envvar="GITLINT_COMMIT", default=None, help="Hash (SHA) of specific commit to lint.")
@click.option("--commits", envvar="GITLINT_COMMITS", default=None,
help="The range of commits (refspec or comma-separated hashes) to lint. [default: HEAD]")
@click.option('-e', '--extra-path', envvar='GITLINT_EXTRA_PATH',
@click.option("-e", "--extra-path", envvar="GITLINT_EXTRA_PATH",
help="Path to a directory or python module with extra user-defined rules",
type=click.Path(exists=True, resolve_path=True, readable=True))
@click.option('--ignore', envvar='GITLINT_IGNORE', default="", help="Ignore rules (comma-separated by id or name).")
@click.option('--contrib', envvar='GITLINT_CONTRIB', default="",
@click.option("--ignore", envvar="GITLINT_IGNORE", default="", help="Ignore rules (comma-separated by id or name).")
@click.option("--contrib", envvar="GITLINT_CONTRIB", default="",
help="Contrib rules to enable (comma-separated by id or name).")
@click.option('--msg-filename', type=click.File(encoding=gitlint.utils.DEFAULT_ENCODING),
@click.option("--msg-filename", type=click.File(encoding=gitlint.utils.FILE_ENCODING),
help="Path to a file containing a commit-msg.")
@click.option('--ignore-stdin', envvar='GITLINT_IGNORE_STDIN', is_flag=True,
@click.option("--ignore-stdin", envvar="GITLINT_IGNORE_STDIN", is_flag=True,
help="Ignore any stdin data. Useful for running in CI server.")
@click.option('--staged', envvar='GITLINT_STAGED', is_flag=True,
@click.option("--staged", envvar="GITLINT_STAGED", is_flag=True,
help="Attempt smart guesses about meta info (like author name, email, branch, changed files, etc) " +
"for staged commits.")
@click.option('--fail-without-commits', envvar='GITLINT_FAIL_WITHOUT_COMMITS', is_flag=True,
@click.option("--fail-without-commits", envvar="GITLINT_FAIL_WITHOUT_COMMITS", is_flag=True,
help="Hard fail when the target commit range is empty.")
@click.option('-v', '--verbose', envvar='GITLINT_VERBOSITY', count=True, default=0,
help="Verbosity, more v's for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv]", )
@click.option('-s', '--silent', envvar='GITLINT_SILENT', is_flag=True,
@click.option("-v", "--verbose", envvar="GITLINT_VERBOSITY", count=True, default=0,
help="Verbosity, use multiple times for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv]", )
@click.option("-s", "--silent", envvar="GITLINT_SILENT", is_flag=True,
help="Silent mode (no output). Takes precedence over -v, -vv, -vvv.")
@click.option('-d', '--debug', envvar='GITLINT_DEBUG', help="Enable debugging output.", is_flag=True)
@click.option("-d", "--debug", envvar="GITLINT_DEBUG", help="Enable debugging output.", is_flag=True)
@click.version_option(version=gitlint.__version__)
@click.pass_context
def cli( # pylint: disable=too-many-arguments
def cli(
ctx, target, config, c, commit, commits, extra_path, ignore, contrib,
msg_filename, ignore_stdin, staged, fail_without_commits, verbose,
silent, debug,
@ -499,5 +496,4 @@ def generate_config(ctx):
# Let's Party!
setup_logging()
if __name__ == "__main__":
# pylint: disable=no-value-for-parameter
cli() # pragma: no cover

View file

@ -1,17 +1,19 @@
from configparser import ConfigParser, Error as ConfigParserError
import copy
import re
import os
import re
import shutil
from collections import OrderedDict
from gitlint.utils import DEFAULT_ENCODING
from gitlint import rules # For some weird reason pylint complains about this, pylint: disable=unused-import
from gitlint import options
from gitlint import rule_finder
from configparser import ConfigParser
from configparser import Error as ConfigParserError
from gitlint import (
options,
rule_finder,
rules,
)
from gitlint.contrib import rules as contrib_rules
from gitlint.exception import GitlintError
from gitlint.utils import FILE_ENCODING
def handle_option_error(func):
@ -31,7 +33,7 @@ class LintConfigError(GitlintError):
pass
class LintConfig: # pylint: disable=too-many-instance-attributes
class LintConfig:
"""Class representing gitlint configuration.
Contains active config as well as number of methods to easily get/set the config.
"""
@ -105,7 +107,7 @@ class LintConfig: # pylint: disable=too-many-instance-attributes
@handle_option_error
def verbosity(self, value):
self._verbosity.set(value)
if self.verbosity < 0 or self.verbosity > 3:
if self.verbosity < 0 or self.verbosity > 3: # noqa: PLR2004 (Magic value used in comparison)
raise LintConfigError("Option 'verbosity' must be set between 0 and 3")
@property
@ -294,7 +296,7 @@ class LintConfig: # pylint: disable=too-many-instance-attributes
if not hasattr(self, attr_name) or attr_name[0] == "_":
raise LintConfigError(f"'{option_name}' is not a valid gitlint option")
# else:
# else
setattr(self, attr_name, option_value)
def __eq__(self, other):
@ -384,7 +386,7 @@ class RuleCollection:
"""Deletes all rules from the collection that match a given attribute name and value"""
# Create a new list based on _rules.values() because in python 3, values() is a ValuesView as opposed to a list
# This means you can't modify the ValueView while iterating over it.
for rule in [r for r in self._rules.values()]: # pylint: disable=unnecessary-comprehension
for rule in list(self._rules.values()):
if hasattr(rule, attr_name) and (getattr(rule, attr_name) == attr_val):
del self._rules[rule.id]
@ -466,7 +468,7 @@ class LintConfigBuilder:
try:
parser = ConfigParser()
with open(filename, encoding=DEFAULT_ENCODING) as config_file:
with open(filename, encoding=FILE_ENCODING) as config_file:
parser.read_file(config_file, filename)
for section_name in parser.sections():
@ -528,14 +530,15 @@ class LintConfigBuilder:
for section_name, section_dict in self._config_blueprint.items():
for option_name, option_value in section_dict.items():
qualified_section_name = section_name
# Skip over the general section, as we've already done that above
if section_name != "general":
if qualified_section_name != "general":
# If the section name contains a colon (:), then this section is defining a Named Rule
# Which means we need to instantiate that Named Rule in the config.
if self.RULE_QUALIFIER_SYMBOL in section_name:
section_name = self._add_named_rule(config, section_name)
qualified_section_name = self._add_named_rule(config, qualified_section_name)
config.set_rule_option(section_name, option_name, option_value)
config.set_rule_option(qualified_section_name, option_name, option_value)
return config

View file

@ -2,7 +2,6 @@ import re
from pathlib import Path
from typing import Tuple
from gitlint.rules import CommitRule, RuleViolation

View file

@ -1,6 +1,5 @@
import logging
LOG = logging.getLogger("gitlint.deprecated")
DEPRECATED_LOG_FORMAT = "%(levelname)s: %(message)s"

View file

@ -1,4 +1,4 @@
from sys import stdout, stderr
from sys import stderr, stdout
class Display:
@ -17,20 +17,20 @@ class Display:
if self.config.verbosity >= verbosity:
stream.write(message + "\n")
def v(self, message, exact=False): # pylint: disable=invalid-name
def v(self, message, exact=False):
self._output(message, 1, exact, stdout)
def vv(self, message, exact=False): # pylint: disable=invalid-name
def vv(self, message, exact=False):
self._output(message, 2, exact, stdout)
def vvv(self, message, exact=False): # pylint: disable=invalid-name
def vvv(self, message, exact=False):
self._output(message, 3, exact, stdout)
def e(self, message, exact=False): # pylint: disable=invalid-name
def e(self, message, exact=False):
self._output(message, 1, exact, stderr)
def ee(self, message, exact=False): # pylint: disable=invalid-name
def ee(self, message, exact=False):
self._output(message, 2, exact, stderr)
def eee(self, message, exact=False): # pylint: disable=invalid-name
def eee(self, message, exact=False):
self._output(message, 3, exact, stderr)

View file

@ -1,4 +1,2 @@
class GitlintError(Exception):
"""Based Exception class for all gitlint exceptions"""
pass

View file

@ -5,13 +5,12 @@ from pathlib import Path
import arrow
from gitlint import shell as sh
from gitlint.cache import PropertyCache, cache
from gitlint.exception import GitlintError
# import exceptions separately, this makes it a little easier to mock them out in the unit tests
from gitlint.shell import CommandNotFound, ErrorReturnCode
from gitlint.cache import PropertyCache, cache
from gitlint.exception import GitlintError
# For now, the git date format we use is fixed, but technically this format is determined by `git config log.date`
# We should fix this at some point :-)
GIT_TIMEFORMAT = "YYYY-MM-DD HH:mm:ss Z"
@ -22,8 +21,6 @@ LOG = logging.getLogger(__name__)
class GitContextError(GitlintError):
"""Exception indicating there is an issue with the git context"""
pass
class GitNotInstalledError(GitContextError):
def __init__(self):
@ -46,7 +43,7 @@ def _git(*command_parts, **kwargs):
git_kwargs.update(kwargs)
try:
LOG.debug(command_parts)
result = sh.git(*command_parts, **git_kwargs) # pylint: disable=unexpected-keyword-arg
result = sh.git(*command_parts, **git_kwargs)
# If we reach this point and the result has an exit_code that is larger than 0, this means that we didn't
# get an exception (which is the default sh behavior for non-zero exit codes) and so the user is expecting
# a non-zero exit code -> just return the entire result
@ -80,7 +77,7 @@ def git_commentchar(repository_path=None):
"""Shortcut for retrieving comment char from git config"""
commentchar = _git("config", "--get", "core.commentchar", _cwd=repository_path, _ok_code=[0, 1])
# git will return an exit code of 1 if it can't find a config value, in this case we fall-back to # as commentchar
if hasattr(commentchar, "exit_code") and commentchar.exit_code == 1: # pylint: disable=no-member
if hasattr(commentchar, "exit_code") and commentchar.exit_code == 1:
commentchar = "#"
return commentchar.replace("\n", "")
@ -174,11 +171,6 @@ class GitChangedFileStats:
def __str__(self) -> str:
return f"{self.filepath}: {self.additions} additions, {self.deletions} deletions"
def __repr__(self) -> str:
return (
f'GitChangedFileStats(filepath="{self.filepath}", additions={self.additions}, deletions={self.deletions})'
)
class GitCommit:
"""Class representing a git commit.
@ -193,7 +185,7 @@ class GitCommit:
message,
sha=None,
date=None,
author_name=None, # pylint: disable=too-many-arguments
author_name=None,
author_email=None,
parents=None,
changed_files_stats=None,
@ -289,7 +281,7 @@ class LocalGitCommit(GitCommit, PropertyCache):
startup time and reduces gitlint's memory footprint.
"""
def __init__(self, context, sha): # pylint: disable=super-init-not-called
def __init__(self, context, sha):
PropertyCache.__init__(self)
self.context = context
self.sha = sha
@ -382,7 +374,7 @@ class StagedLocalGitCommit(GitCommit, PropertyCache):
information.
"""
def __init__(self, context, commit_message): # pylint: disable=super-init-not-called
def __init__(self, context, commit_message):
PropertyCache.__init__(self)
self.context = context
self.message = commit_message

View file

@ -1,10 +1,10 @@
import shutil
import os
import shutil
import stat
from gitlint.utils import DEFAULT_ENCODING
from gitlint.git import git_hooks_dir
from gitlint.exception import GitlintError
from gitlint.git import git_hooks_dir
from gitlint.utils import FILE_ENCODING
COMMIT_MSG_HOOK_SRC_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "files", "commit-msg")
COMMIT_MSG_HOOK_DST_PATH = "commit-msg"
@ -52,9 +52,9 @@ class GitHookInstaller:
if not os.path.exists(dest_path):
raise GitHookInstallerError(f"There is no commit-msg hook present in {dest_path}.")
with open(dest_path, encoding=DEFAULT_ENCODING) as fp:
with open(dest_path, encoding=FILE_ENCODING) as fp:
lines = fp.readlines()
if len(lines) < 2 or lines[1] != GITLINT_HOOK_IDENTIFIER:
if len(lines) < 2 or lines[1] != GITLINT_HOOK_IDENTIFIER: # noqa: PLR2004 (Magic value used in comparison)
msg = (
f"The commit-msg hook in {dest_path} was not installed by gitlint (or it was modified).\n"
"Uninstallation of 3th party or modified gitlint hooks is not supported."

View file

@ -1,7 +1,7 @@
# pylint: disable=logging-not-lazy
import logging
from gitlint import rules as gitlint_rules
from gitlint import display
from gitlint import rules as gitlint_rules
from gitlint.deprecation import Deprecation
LOG = logging.getLogger(__name__)

View file

@ -1,6 +1,6 @@
from abc import abstractmethod
import os
import re
from abc import abstractmethod
from gitlint.exception import GitlintError
@ -37,7 +37,6 @@ class RuleOption:
@abstractmethod
def set(self, value):
"""Validates and sets the option's value"""
pass # pragma: no cover
def __str__(self):
return f"({self.name}: {self.value} ({self.description}))"

View file

@ -1,10 +1,10 @@
import fnmatch
import importlib
import inspect
import os
import sys
import importlib
from gitlint import rules, options
from gitlint import options, rules
def find_rule_classes(extra_path):
@ -55,7 +55,7 @@ def find_rule_classes(extra_path):
importlib.import_module(module)
except Exception as e:
raise rules.UserRuleError(f"Error while importing extra-path module '{module}': {e}")
raise rules.UserRuleError(f"Error while importing extra-path module '{module}': {e}") from e
# Find all rule classes in the module. We do this my inspecting all members of the module and checking
# 1) is it a class, if not, skip
@ -67,11 +67,7 @@ def find_rule_classes(extra_path):
for _, clazz in inspect.getmembers(sys.modules[module])
if inspect.isclass(clazz) # check isclass to ensure clazz.__module__ exists
and clazz.__module__ == module # ignore imported classes
and (
issubclass(clazz, rules.LineRule)
or issubclass(clazz, rules.CommitRule)
or issubclass(clazz, rules.ConfigurationRule)
)
and (issubclass(clazz, (rules.LineRule, rules.CommitRule, rules.ConfigurationRule)))
]
)
@ -82,7 +78,7 @@ def find_rule_classes(extra_path):
return rule_classes
def assert_valid_rule_class(clazz, rule_type="User-defined"): # pylint: disable=too-many-branches
def assert_valid_rule_class(clazz, rule_type="User-defined"): # noqa: PLR0912 (too many branches)
"""
Asserts that a given rule clazz is valid by checking a number of its properties:
- Rules must extend from LineRule, CommitRule or ConfigurationRule
@ -97,11 +93,7 @@ def assert_valid_rule_class(clazz, rule_type="User-defined"): # pylint: disable
"""
# Rules must extend from LineRule, CommitRule or ConfigurationRule
if not (
issubclass(clazz, rules.LineRule)
or issubclass(clazz, rules.CommitRule)
or issubclass(clazz, rules.ConfigurationRule)
):
if not issubclass(clazz, (rules.LineRule, rules.CommitRule, rules.ConfigurationRule)):
msg = (
f"{rule_type} rule class '{clazz.__name__}' "
f"must extend from {rules.CommitRule.__module__}.{rules.LineRule.__name__}, "
@ -142,17 +134,18 @@ def assert_valid_rule_class(clazz, rule_type="User-defined"): # pylint: disable
# Line/Commit rules must have a `validate` method
# We use isroutine() as it's both python 2 and 3 compatible. Details: http://stackoverflow.com/a/17019998/381010
if issubclass(clazz, rules.LineRule) or issubclass(clazz, rules.CommitRule):
if issubclass(clazz, (rules.LineRule, rules.CommitRule)):
if not hasattr(clazz, "validate") or not inspect.isroutine(clazz.validate):
raise rules.UserRuleError(f"{rule_type} rule class '{clazz.__name__}' must have a 'validate' method")
# Configuration rules must have an `apply` method
elif issubclass(clazz, rules.ConfigurationRule):
elif issubclass(clazz, rules.ConfigurationRule): # noqa: SIM102
if not hasattr(clazz, "apply") or not inspect.isroutine(clazz.apply):
msg = f"{rule_type} Configuration rule class '{clazz.__name__}' must have an 'apply' method"
raise rules.UserRuleError(msg)
# LineRules must have a valid target: rules.CommitMessageTitle or rules.CommitMessageBody
if issubclass(clazz, rules.LineRule):
if issubclass(clazz, rules.LineRule): # noqa: SIM102
if clazz.target not in [rules.CommitMessageTitle, rules.CommitMessageBody]:
msg = (
f"The target attribute of the {rule_type.lower()} LineRule class '{clazz.__name__}' "

View file

@ -1,11 +1,10 @@
# pylint: disable=inconsistent-return-statements
import copy
import logging
import re
from gitlint.options import IntOption, BoolOption, StrOption, ListOption, RegexOption
from gitlint.exception import GitlintError
from gitlint.deprecation import Deprecation
from gitlint.exception import GitlintError
from gitlint.options import BoolOption, IntOption, ListOption, RegexOption, StrOption
class Rule:
@ -50,40 +49,28 @@ class Rule:
class ConfigurationRule(Rule):
"""Class representing rules that can dynamically change the configuration of gitlint during runtime."""
pass
class CommitRule(Rule):
"""Class representing rules that act on an entire commit at once"""
pass
class LineRule(Rule):
"""Class representing rules that act on a line by line basis"""
pass
class LineRuleTarget:
"""Base class for LineRule targets. A LineRuleTarget specifies where a given rule will be applied
(e.g. commit message title, commit message body).
Each LineRule MUST have a target specified."""
pass
class CommitMessageTitle(LineRuleTarget):
"""Target class used for rules that apply to a commit message title"""
pass
class CommitMessageBody(LineRuleTarget):
"""Target class used for rules that apply to a commit message body"""
pass
class RuleViolation:
"""Class representing a violation of a rule. I.e.: When a rule is broken, the rule will instantiate this class
@ -107,8 +94,6 @@ class RuleViolation:
class UserRuleError(GitlintError):
"""Error used to indicate that an error occurred while trying to load a user rule"""
pass
class MaxLineLength(LineRule):
name = "max-line-length"
@ -305,7 +290,7 @@ class BodyMissing(CommitRule):
# ignore merges when option tells us to, which may have no body
if self.options["ignore-merge-commits"].value and commit.is_merge_commit:
return
if len(commit.message.body) < 2 or not "".join(commit.message.body).strip():
if len(commit.message.body) < 2 or not "".join(commit.message.body).strip(): # noqa: PLR2004 (Magic value)
return [RuleViolation(self.id, "Body message is missing", None, 3)]
@ -319,7 +304,7 @@ class BodyChangedFileMention(CommitRule):
for needs_mentioned_file in self.options["files"].value:
# if a file that we need to look out for is actually changed, then check whether it occurs
# in the commit msg body
if needs_mentioned_file in commit.changed_files:
if needs_mentioned_file in commit.changed_files: # noqa: SIM102
if needs_mentioned_file not in " ".join(commit.message.body):
violation_message = f"Body does not mention changed file '{needs_mentioned_file}'"
violations.append(RuleViolation(self.id, violation_message, None, len(commit.message.body) + 1))
@ -370,7 +355,7 @@ class AuthorValidEmail(CommitRule):
# We're replacing regex match with search semantics, see https://github.com/jorisroovers/gitlint/issues/254
# In case the user is using the default regex, we can silently change to using search
# If not, it depends on config (handled by Deprecation class)
if self.DEFAULT_AUTHOR_VALID_EMAIL_REGEX == self.options["regex"].value.pattern:
if self.options["regex"].value.pattern == self.DEFAULT_AUTHOR_VALID_EMAIL_REGEX:
regex_method = self.options["regex"].value.search
else:
regex_method = Deprecation.get_regex_method(self, self.options["regex"])
@ -458,7 +443,7 @@ class IgnoreBodyLines(ConfigurationRule):
new_body.append(line)
commit.message.body = new_body
commit.message.full = "\n".join([commit.message.title] + new_body)
commit.message.full = "\n".join([commit.message.title, *new_body])
class IgnoreByAuthorName(ConfigurationRule):
@ -474,6 +459,17 @@ class IgnoreByAuthorName(ConfigurationRule):
if not self.options["regex"].value:
return
# If commit.author_name is not available, log warning and return
if commit.author_name is None:
warning_msg = (
"%s - %s: skipping - commit.author_name unknown. "
"Suggested fix: Use the --staged flag (or set general.staged=True in .gitlint). "
"More details: https://jorisroovers.com/gitlint/configuration/#staged"
)
self.log.warning(warning_msg, self.name, self.id)
return
regex_method = Deprecation.get_regex_method(self, self.options["regex"])
if regex_method(commit.author_name):

View file

@ -5,7 +5,8 @@ capabilities wrt dealing with more edge-case environments on *nix systems that a
"""
import subprocess
from gitlint.utils import USE_SH_LIB, DEFAULT_ENCODING
from gitlint.utils import TERMINAL_ENCODING, USE_SH_LIB
def shell(cmd):
@ -15,17 +16,17 @@ def shell(cmd):
if USE_SH_LIB:
from sh import git # pylint: disable=unused-import,import-error
# import exceptions separately, this makes it a little easier to mock them out in the unit tests
from sh import CommandNotFound, ErrorReturnCode # pylint: disable=import-error
from sh import (
CommandNotFound,
ErrorReturnCode,
git,
)
else:
class CommandNotFound(Exception):
"""Exception indicating a command was not found during execution"""
pass
class ShResult:
"""Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using
the builtin subprocess module"""
@ -42,14 +43,12 @@ else:
class ErrorReturnCode(ShResult, Exception):
"""ShResult subclass for unexpected results (acts as an exception)."""
pass
def git(*command_parts, **kwargs):
"""Git shell wrapper.
Implemented as separate function here, so we can do a 'sh' style imports:
`from shell import git`
"""
args = ["git"] + list(command_parts)
args = ["git", *list(command_parts)]
return _exec(*args, **kwargs)
def _exec(*args, **kwargs):
@ -65,7 +64,7 @@ else:
raise CommandNotFound from e
exit_code = p.returncode
stdout = result[0].decode(DEFAULT_ENCODING)
stdout = result[0].decode(TERMINAL_ENCODING)
stderr = result[1] # 'sh' does not decode the stderr bytes to unicode
full_cmd = "" if args is None else " ".join(args)

View file

@ -5,15 +5,15 @@ import os
import re
import shutil
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from gitlint.config import LintConfig
from gitlint.deprecation import Deprecation, LOG as DEPRECATION_LOG
from gitlint.git import GitContext, GitChangedFileStats
from gitlint.utils import LOG_FORMAT, DEFAULT_ENCODING
from gitlint.deprecation import LOG as DEPRECATION_LOG
from gitlint.deprecation import Deprecation
from gitlint.git import GitChangedFileStats, GitContext
from gitlint.utils import FILE_ENCODING, LOG_FORMAT
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING = (
"WARNING: gitlint.deprecated.regex_style_search {0} - {1}: gitlint will be switching from using "
@ -30,10 +30,28 @@ class BaseTestCase(unittest.TestCase):
# In case of assert failures, print the full error message
maxDiff = None
# Working directory in which tests in this class are executed
working_dir = None
# Originally working dir when the test was started
original_working_dir = None
SAMPLES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "samples")
EXPECTED_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "expected")
GITLINT_USE_SH_LIB = os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]")
@classmethod
def setUpClass(cls):
# Run tests a temporary directory to shield them from any local git config
cls.original_working_dir = os.getcwd()
cls.working_dir = tempfile.mkdtemp()
os.chdir(cls.working_dir)
@classmethod
def tearDownClass(cls):
# Go back to original working dir and remove our temp working dir
os.chdir(cls.original_working_dir)
shutil.rmtree(cls.working_dir)
def setUp(self):
self.logcapture = LogCapture()
self.logcapture.setFormatter(logging.Formatter(LOG_FORMAT))
@ -77,9 +95,7 @@ class BaseTestCase(unittest.TestCase):
def get_sample(filename=""):
"""Read and return the contents of a file in gitlint/tests/samples"""
sample_path = BaseTestCase.get_sample_path(filename)
with open(sample_path, encoding=DEFAULT_ENCODING) as content:
sample = content.read()
return sample
return Path(sample_path).read_text(encoding=FILE_ENCODING)
@staticmethod
def patch_input(side_effect):
@ -93,8 +109,7 @@ class BaseTestCase(unittest.TestCase):
"""Utility method to read an expected file from gitlint/tests/expected and return it as a string.
Optionally replace template variables specified by variable_dict."""
expected_path = os.path.join(BaseTestCase.EXPECTED_DIR, filename)
with open(expected_path, encoding=DEFAULT_ENCODING) as content:
expected = content.read()
expected = Path(expected_path).read_text(encoding=FILE_ENCODING)
if variable_dict:
expected = expected.format(**variable_dict)
@ -150,22 +165,24 @@ class BaseTestCase(unittest.TestCase):
self.logcapture.clear()
@contextlib.contextmanager
def assertRaisesMessage(self, expected_exception, expected_msg): # pylint: disable=invalid-name
def assertRaisesMessage(self, expected_exception, expected_msg):
"""Asserts an exception has occurred with a given error message"""
try:
yield
except expected_exception as exc:
exception_msg = str(exc)
if exception_msg != expected_msg:
if exception_msg != expected_msg: # pragma: nocover
error = f"Right exception, wrong message:\n got: {exception_msg}\n expected: {expected_msg}"
raise self.fail(error)
raise self.fail(error) from exc
# else: everything is fine, just return
return
except Exception as exc:
raise self.fail(f"Expected '{expected_exception.__name__}' got '{exc.__class__.__name__}'")
except Exception as exc: # pragma: nocover
raise self.fail(f"Expected '{expected_exception.__name__}' got '{exc.__class__.__name__}'") from exc
# No exception raised while we expected one
raise self.fail(f"Expected to raise {expected_exception.__name__}, didn't get an exception at all")
raise self.fail(
f"Expected to raise {expected_exception.__name__}, didn't get an exception at all"
) # pragma: nocover
def object_equality_test(self, obj, attr_list, ctor_kwargs=None):
"""Helper function to easily implement object equality tests.

View file

@ -1,22 +1,15 @@
import io
import os
import sys
import platform
import arrow
import sys
from io import StringIO
from click.testing import CliRunner
from unittest.mock import patch
import arrow
from click.testing import CliRunner
from gitlint import __version__, cli
from gitlint.shell import CommandNotFound
from gitlint.tests.base import BaseTestCase
from gitlint import cli
from gitlint import __version__
from gitlint.utils import DEFAULT_ENCODING
from gitlint.utils import FILE_ENCODING, TERMINAL_ENCODING
class CLITests(BaseTestCase):
@ -46,7 +39,8 @@ class CLITests(BaseTestCase):
"gitlint_version": __version__,
"GITLINT_USE_SH_LIB": BaseTestCase.GITLINT_USE_SH_LIB,
"target": os.path.realpath(os.getcwd()),
"DEFAULT_ENCODING": DEFAULT_ENCODING,
"TERMINAL_ENCODING": TERMINAL_ENCODING,
"FILE_ENCODING": FILE_ENCODING,
}
def test_version(self):
@ -105,6 +99,40 @@ class CLITests(BaseTestCase):
self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli/test_lint_multiple_commits_1"))
self.assertEqual(result.exit_code, 3)
@patch("gitlint.cli.get_stdin_data", return_value=False)
@patch("gitlint.git.sh")
def test_lint_multiple_commits_csv(self, sh, _):
"""Test for --commits option"""
# fmt: off
sh.git.side_effect = [
"6f29bf81a8322a04071bb794666e48c443a90360\n", # git rev-list <SHA>
"25053ccec5e28e1bb8f7551fdbb5ab213ada2401\n",
"4da2656b0dadc76c7ee3fd0243a96cb64007f125\n",
# git log --pretty <FORMAT> <SHA>
"test åuthor1\x00test-email1@föo.com\x002016-12-03 15:28:15 +0100\x00åbc\n"
"commït-title1\n\ncommït-body1",
"#", # git config --get core.commentchar
"3\t5\tcommit-1/file-1\n1\t4\tcommit-1/file-2\n", # git diff-tree
"commit-1-branch-1\ncommit-1-branch-2\n", # git branch --contains <sha>
# git log --pretty <FORMAT> <SHA>
"test åuthor2\x00test-email3@föo.com\x002016-12-04 15:28:15 +0100\x00åbc\n"
"commït-title2\n\ncommït-body2",
"8\t3\tcommit-2/file-1\n1\t5\tcommit-2/file-2\n", # git diff-tree
"commit-2-branch-1\ncommit-2-branch-2\n", # git branch --contains <sha>
# git log --pretty <FORMAT> <SHA>
"test åuthor3\x00test-email3@föo.com\x002016-12-05 15:28:15 +0100\x00åbc\n"
"commït-title3\n\ncommït-body3",
"7\t2\tcommit-3/file-1\n1\t7\tcommit-3/file-2\n", # git diff-tree
"commit-3-branch-1\ncommit-3-branch-2\n", # git branch --contains <sha>
]
# fmt: on
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--commits", "6f29bf81,25053cce,4da2656b"])
self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli/test_lint_multiple_commits_csv_1"))
self.assertEqual(result.exit_code, 3)
@patch("gitlint.cli.get_stdin_data", return_value=False)
@patch("gitlint.git.sh")
def test_lint_multiple_commits_config(self, sh, _):
@ -225,8 +253,7 @@ class CLITests(BaseTestCase):
self.assertEqual(result.exit_code, 2)
@patch("gitlint.cli.get_stdin_data", return_value=False)
@patch("gitlint.git.sh")
def test_lint_commit_negative(self, sh, _):
def test_lint_commit_negative(self, _):
"""Negative test for --commit option"""
# Try using --commit and --commits at the same time (not allowed)
@ -298,6 +325,11 @@ class CLITests(BaseTestCase):
self.assertEqual(result.output, "")
expected_kwargs = self.get_system_info_dict()
changed_files_stats = (
f" {os.path.join('commit-1', 'file-1')}: 1 additions, 5 deletions\n"
f" {os.path.join('commit-1', 'file-2')}: 8 additions, 9 deletions"
)
expected_kwargs.update({"changed_files_stats": changed_files_stats})
expected_logs = self.get_expected("cli/test_cli/test_lint_staged_stdin_2", expected_kwargs)
self.assert_logged(expected_logs)
@ -318,7 +350,7 @@ class CLITests(BaseTestCase):
with self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "msg")
with open(msg_filename, "w", encoding=DEFAULT_ENCODING) as f:
with open(msg_filename, "w", encoding=FILE_ENCODING) as f:
f.write("WIP: msg-filename tïtle\n")
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
@ -328,6 +360,11 @@ class CLITests(BaseTestCase):
self.assertEqual(result.output, "")
expected_kwargs = self.get_system_info_dict()
changed_files_stats = (
f" {os.path.join('commit-1', 'file-1')}: 3 additions, 4 deletions\n"
f" {os.path.join('commit-1', 'file-2')}: 4 additions, 7 deletions"
)
expected_kwargs.update({"changed_files_stats": changed_files_stats})
expected_logs = self.get_expected("cli/test_cli/test_lint_staged_msg_filename_2", expected_kwargs)
self.assert_logged(expected_logs)
@ -368,7 +405,7 @@ class CLITests(BaseTestCase):
with self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "msg")
with open(msg_filename, "w", encoding=DEFAULT_ENCODING) as f:
with open(msg_filename, "w", encoding=FILE_ENCODING) as f:
f.write("Commït title\n")
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
@ -458,6 +495,25 @@ class CLITests(BaseTestCase):
self.assertEqual(result.exit_code, 6)
expected_kwargs = self.get_system_info_dict()
changed_files_stats1 = (
f" {os.path.join('commit-1', 'file-1')}: 5 additions, 8 deletions\n"
f" {os.path.join('commit-1', 'file-2')}: 2 additions, 9 deletions"
)
changed_files_stats2 = (
f" {os.path.join('commit-2', 'file-1')}: 5 additions, 8 deletions\n"
f" {os.path.join('commit-2', 'file-2')}: 7 additions, 9 deletions"
)
changed_files_stats3 = (
f" {os.path.join('commit-3', 'file-1')}: 1 additions, 4 deletions\n"
f" {os.path.join('commit-3', 'file-2')}: 3 additions, 4 deletions"
)
expected_kwargs.update(
{
"changed_files_stats1": changed_files_stats1,
"changed_files_stats2": changed_files_stats2,
"changed_files_stats3": changed_files_stats3,
}
)
expected_kwargs.update({"config_path": config_path})
expected_logs = self.get_expected("cli/test_cli/test_debug_1", expected_kwargs)
self.assert_logged(expected_logs)
@ -548,7 +604,7 @@ class CLITests(BaseTestCase):
# Non existing file
config_path = self.get_sample_path("föo")
result = self.cli.invoke(cli.cli, ["--config", config_path])
expected_string = f"Error: Invalid value for '-C' / '--config': File '{config_path}' does not exist."
expected_string = f"Error: Invalid value for '-C' / '--config': File {config_path!r} does not exist."
self.assertEqual(result.output.split("\n")[3], expected_string)
self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE)
@ -569,7 +625,7 @@ class CLITests(BaseTestCase):
# Non existing file
config_path = self.get_sample_path("föo")
result = self.cli.invoke(cli.cli, env={"GITLINT_CONFIG": config_path})
expected_string = f"Error: Invalid value for '-C' / '--config': File '{config_path}' does not exist."
expected_string = f"Error: Invalid value for '-C' / '--config': File {config_path!r} does not exist."
self.assertEqual(result.output.split("\n")[3], expected_string)
self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE)
@ -578,6 +634,11 @@ class CLITests(BaseTestCase):
result = self.cli.invoke(cli.cli, env={"GITLINT_CONFIG": config_path})
self.assertEqual(result.exit_code, self.CONFIG_ERROR_CODE)
def test_config_error(self):
result = self.cli.invoke(cli.cli, ["-c", "foo.bar=hur"])
self.assertEqual(result.output, "Config Error: No such rule 'foo'\n")
self.assertEqual(result.exit_code, self.CONFIG_ERROR_CODE)
@patch("gitlint.cli.get_stdin_data", return_value=False)
def test_target(self, _):
"""Test for the --target option"""
@ -602,7 +663,7 @@ class CLITests(BaseTestCase):
target_path = self.get_sample_path(os.path.join("config", "gitlintconfig"))
result = self.cli.invoke(cli.cli, ["--target", target_path])
self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE)
expected_msg = f"Error: Invalid value for '--target': Directory '{target_path}' is a file."
expected_msg = f"Error: Invalid value for '--target': Directory {target_path!r} is a file."
self.assertEqual(result.output.split("\n")[3], expected_msg)
@patch("gitlint.config.LintConfigGenerator.generate_config")

View file

@ -1,18 +1,12 @@
import io
from io import StringIO
import os
from click.testing import CliRunner
from io import StringIO
from unittest.mock import patch
from gitlint.tests.base import BaseTestCase
from gitlint import cli
from gitlint import hooks
from gitlint import config
from click.testing import CliRunner
from gitlint import cli, config, hooks
from gitlint.shell import ErrorReturnCode
from gitlint.utils import DEFAULT_ENCODING
from gitlint.tests.base import BaseTestCase
from gitlint.utils import FILE_ENCODING
class CLIHookTests(BaseTestCase):
@ -108,7 +102,7 @@ class CLIHookTests(BaseTestCase):
with self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "hür")
with open(msg_filename, "w", encoding=DEFAULT_ENCODING) as f:
with open(msg_filename, "w", encoding=FILE_ENCODING) as f:
f.write("WIP: tïtle\n")
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
@ -134,68 +128,65 @@ class CLIHookTests(BaseTestCase):
# When set_editors[i] == None, ensure we don't fallback to EDITOR set in shell invocating the tests
os.environ.pop("EDITOR", None)
with self.patch_input(["e", "e", "n"]):
with self.tempdir() as tmpdir:
msg_filename = os.path.realpath(os.path.join(tmpdir, "hür"))
with open(msg_filename, "w", encoding=DEFAULT_ENCODING) as f:
f.write(commit_messages[i] + "\n")
with self.patch_input(["e", "e", "n"]), self.tempdir() as tmpdir:
msg_filename = os.path.realpath(os.path.join(tmpdir, "hür"))
with open(msg_filename, "w", encoding=FILE_ENCODING) as f:
f.write(commit_messages[i] + "\n")
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--msg-filename", msg_filename, "run-hook"])
self.assertEqual(
result.output,
self.get_expected(
"cli/test_cli_hooks/test_hook_edit_1_stdout", {"commit_msg": commit_messages[i]}
),
)
expected = self.get_expected(
"cli/test_cli_hooks/test_hook_edit_1_stderr", {"commit_msg": commit_messages[i]}
)
self.assertEqual(stderr.getvalue(), expected)
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--msg-filename", msg_filename, "run-hook"])
self.assertEqual(
result.output,
self.get_expected(
"cli/test_cli_hooks/test_hook_edit_1_stdout", {"commit_msg": commit_messages[i]}
),
)
expected = self.get_expected(
"cli/test_cli_hooks/test_hook_edit_1_stderr", {"commit_msg": commit_messages[i]}
)
self.assertEqual(stderr.getvalue(), expected)
# exit code = number of violations
self.assertEqual(result.exit_code, 2)
# exit code = number of violations
self.assertEqual(result.exit_code, 2)
shell.assert_called_with(expected_editors[i] + " " + msg_filename)
self.assert_log_contains("DEBUG: gitlint.cli run-hook: editing commit message")
self.assert_log_contains(f"DEBUG: gitlint.cli run-hook: {expected_editors[i]} {msg_filename}")
shell.assert_called_with(expected_editors[i] + " " + msg_filename)
self.assert_log_contains("DEBUG: gitlint.cli run-hook: editing commit message")
self.assert_log_contains(f"DEBUG: gitlint.cli run-hook: {expected_editors[i]} {msg_filename}")
def test_run_hook_no(self):
"""Test for run-hook subcommand, answering 'n(o)' after commit-hook"""
with self.patch_input(["n"]):
with self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "hür")
with open(msg_filename, "w", encoding=DEFAULT_ENCODING) as f:
f.write("WIP: höok no\n")
with self.patch_input(["n"]), self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "hür")
with open(msg_filename, "w", encoding=FILE_ENCODING) as f:
f.write("WIP: höok no\n")
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--msg-filename", msg_filename, "run-hook"])
self.assertEqual(result.output, self.get_expected("cli/test_cli_hooks/test_hook_no_1_stdout"))
self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli_hooks/test_hook_no_1_stderr"))
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--msg-filename", msg_filename, "run-hook"])
self.assertEqual(result.output, self.get_expected("cli/test_cli_hooks/test_hook_no_1_stdout"))
self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli_hooks/test_hook_no_1_stderr"))
# We decided not to keep the commit message: hook returns number of violations (>0)
# This will cause git to abort the commit
self.assertEqual(result.exit_code, 2)
self.assert_log_contains("DEBUG: gitlint.cli run-hook: commit message declined")
# We decided not to keep the commit message: hook returns number of violations (>0)
# This will cause git to abort the commit
self.assertEqual(result.exit_code, 2)
self.assert_log_contains("DEBUG: gitlint.cli run-hook: commit message declined")
def test_run_hook_yes(self):
"""Test for run-hook subcommand, answering 'y(es)' after commit-hook"""
with self.patch_input(["y"]):
with self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "hür")
with open(msg_filename, "w", encoding=DEFAULT_ENCODING) as f:
f.write("WIP: höok yes\n")
with self.patch_input(["y"]), self.tempdir() as tmpdir:
msg_filename = os.path.join(tmpdir, "hür")
with open(msg_filename, "w", encoding=FILE_ENCODING) as f:
f.write("WIP: höok yes\n")
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--msg-filename", msg_filename, "run-hook"])
self.assertEqual(result.output, self.get_expected("cli/test_cli_hooks/test_hook_yes_1_stdout"))
self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli_hooks/test_hook_yes_1_stderr"))
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--msg-filename", msg_filename, "run-hook"])
self.assertEqual(result.output, self.get_expected("cli/test_cli_hooks/test_hook_yes_1_stdout"))
self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli_hooks/test_hook_yes_1_stderr"))
# Exit code is 0 because we decide to keep the commit message
# This will cause git to keep the commit
self.assertEqual(result.exit_code, 0)
self.assert_log_contains("DEBUG: gitlint.cli run-hook: commit message accepted")
# Exit code is 0 because we decide to keep the commit message
# This will cause git to keep the commit
self.assertEqual(result.exit_code, 0)
self.assert_log_contains("DEBUG: gitlint.cli run-hook: commit message accepted")
@patch("gitlint.cli.get_stdin_data", return_value=False)
@patch("gitlint.git.sh")
@ -207,7 +198,8 @@ class CLIHookTests(BaseTestCase):
error_msg = b"fatal: not a git repository (or any of the parent directories): .git"
sh.git.side_effect = ErrorReturnCode("full command", b"stdout", error_msg)
result = self.cli.invoke(cli.cli, ["run-hook"])
expected = self.get_expected("cli/test_cli_hooks/test_run_hook_negative_1", {"git_repo": os.getcwd()})
expected_kwargs = {"git_repo": os.path.realpath(os.getcwd())}
expected = self.get_expected("cli/test_cli_hooks/test_run_hook_negative_1", expected_kwargs)
self.assertEqual(result.output, expected)
self.assertEqual(result.exit_code, self.GIT_CONTEXT_ERROR_CODE)
@ -276,11 +268,10 @@ class CLIHookTests(BaseTestCase):
"commit-1-branch-1\ncommit-1-branch-2\n",
]
with self.patch_input(["e"]):
with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["run-hook"])
expected = self.get_expected("cli/test_cli_hooks/test_hook_local_commit_1_stderr")
self.assertEqual(stderr.getvalue(), expected)
self.assertEqual(result.output, self.get_expected("cli/test_cli_hooks/test_hook_local_commit_1_stdout"))
# If we can't edit the message, run-hook follows regular gitlint behavior and exit code = # violations
self.assertEqual(result.exit_code, 2)
with self.patch_input(["e"]), patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["run-hook"])
expected = self.get_expected("cli/test_cli_hooks/test_hook_local_commit_1_stderr")
self.assertEqual(stderr.getvalue(), expected)
self.assertEqual(result.output, self.get_expected("cli/test_cli_hooks/test_hook_local_commit_1_stdout"))
# If we can't edit the message, run-hook follows regular gitlint behavior and exit code = # violations
self.assertEqual(result.exit_code, 2)

View file

@ -1,8 +1,12 @@
from unittest.mock import patch
from gitlint import rules
from gitlint.config import LintConfig, LintConfigError, LintConfigGenerator, GITLINT_CONFIG_TEMPLATE_SRC_PATH
from gitlint import options
from gitlint import options, rules
from gitlint.config import (
GITLINT_CONFIG_TEMPLATE_SRC_PATH,
LintConfig,
LintConfigError,
LintConfigGenerator,
)
from gitlint.tests.base import BaseTestCase
@ -166,7 +170,7 @@ class LintConfigTests(BaseTestCase):
# UserRuleError, RuleOptionError should be re-raised as LintConfigErrors
side_effects = [rules.UserRuleError("üser-rule"), options.RuleOptionError("rüle-option")]
for side_effect in side_effects:
with patch("gitlint.config.rule_finder.find_rule_classes", side_effect=side_effect):
with patch("gitlint.config.rule_finder.find_rule_classes", side_effect=side_effect): # noqa: SIM117
with self.assertRaisesMessage(LintConfigError, str(side_effect)):
config.contrib = "contrib-title-conventional-commits"

View file

@ -1,10 +1,8 @@
import copy
from gitlint.tests.base import BaseTestCase
from gitlint.config import LintConfig, LintConfigBuilder, LintConfigError
from gitlint import rules
from gitlint.config import LintConfig, LintConfigBuilder, LintConfigError
from gitlint.tests.base import BaseTestCase
class LintConfigBuilderTests(BaseTestCase):
@ -256,8 +254,7 @@ class LintConfigBuilderTests(BaseTestCase):
my_rule.options["regex"].set("wrong")
def test_named_rules_negative(self):
# T7 = title-match-regex
# Invalid rule name
# Invalid rule name (T7 = title-match-regex)
for invalid_name in ["", " ", " ", "\t", "\n", "å b", "å:b", "åb:", ":åb"]:
config_builder = LintConfigBuilder()
config_builder.set_option(f"T7:{invalid_name}", "regex", "tëst")

View file

@ -1,12 +1,10 @@
from io import StringIO
from click.testing import CliRunner
from unittest.mock import patch
from gitlint.tests.base import BaseTestCase
from click.testing import CliRunner
from gitlint import cli
from gitlint.config import LintConfigBuilder
from gitlint.tests.base import BaseTestCase
class LintConfigPrecedenceTests(BaseTestCase):

View file

@ -1,4 +1,5 @@
from collections import OrderedDict
from gitlint import rules
from gitlint.config import RuleCollection
from gitlint.tests.base import BaseTestCase

View file

@ -1,10 +1,10 @@
from collections import namedtuple
from unittest.mock import patch
from gitlint.tests.base import BaseTestCase
from gitlint.rules import RuleViolation
from gitlint.config import LintConfig
from gitlint.config import LintConfig
from gitlint.contrib.rules.authors_commit import AllowedAuthors
from gitlint.rules import RuleViolation
from gitlint.tests.base import BaseTestCase
class ContribAuthorsCommitTests(BaseTestCase):
@ -101,6 +101,5 @@ class ContribAuthorsCommitTests(BaseTestCase):
return_value=False,
)
def test_read_authors_file_missing_file(self, _mock_iterdir):
with self.assertRaises(FileNotFoundError) as err:
with self.assertRaisesMessage(FileNotFoundError, "No AUTHORS file found!"):
AllowedAuthors._read_authors_from_file(self.gitcontext)
self.assertEqual(err.exception.args[0], "AUTHORS file not found")

View file

@ -1,7 +1,7 @@
from gitlint.tests.base import BaseTestCase
from gitlint.rules import RuleViolation
from gitlint.contrib.rules.conventional_commit import ConventionalCommit
from gitlint.config import LintConfig
from gitlint.contrib.rules.conventional_commit import ConventionalCommit
from gitlint.rules import RuleViolation
from gitlint.tests.base import BaseTestCase
class ContribConventionalCommitTests(BaseTestCase):

View file

@ -1,8 +1,7 @@
from gitlint.tests.base import BaseTestCase
from gitlint.rules import RuleViolation
from gitlint.contrib.rules.disallow_cleanup_commits import DisallowCleanupCommits
from gitlint.config import LintConfig
from gitlint.contrib.rules.disallow_cleanup_commits import DisallowCleanupCommits
from gitlint.rules import RuleViolation
from gitlint.tests.base import BaseTestCase
class ContribDisallowCleanupCommitsTest(BaseTestCase):

View file

@ -1,8 +1,7 @@
from gitlint.tests.base import BaseTestCase
from gitlint.rules import RuleViolation
from gitlint.contrib.rules.signedoff_by import SignedOffBy
from gitlint.config import LintConfig
from gitlint.contrib.rules.signedoff_by import SignedOffBy
from gitlint.rules import RuleViolation
from gitlint.tests.base import BaseTestCase
class ContribSignedOffByTests(BaseTestCase):

View file

@ -1,9 +1,9 @@
import os
from gitlint.tests.base import BaseTestCase
from gitlint.contrib import rules as contrib_rules
from gitlint.tests.contrib import rules as contrib_tests
from gitlint import rule_finder, rules
from gitlint.contrib import rules as contrib_rules
from gitlint.tests.base import BaseTestCase
from gitlint.tests.contrib import rules as contrib_tests
class ContribRuleTests(BaseTestCase):

View file

@ -4,7 +4,8 @@ DEBUG: gitlint.cli Python version: {python_version}
DEBUG: gitlint.cli Git version: git version 1.2.3
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: {config_path}
[GENERAL]
@ -88,8 +89,7 @@ Parents: ['a123']
Branches: ['commit-1-branch-1', 'commit-1-branch-2']
Changed Files: ['commit-1/file-1', 'commit-1/file-2']
Changed Files Stats:
commit-1/file-1: 5 additions, 8 deletions
commit-1/file-2: 2 additions, 9 deletions
{changed_files_stats1}
-----------------------
DEBUG: gitlint.git ('log', '25053ccec5e28e1bb8f7551fdbb5ab213ada2401', '-1', '--pretty=%aN%x00%aE%x00%ai%x00%P%n%B')
DEBUG: gitlint.lint Linting commit 25053ccec5e28e1bb8f7551fdbb5ab213ada2401
@ -112,8 +112,7 @@ Parents: ['b123']
Branches: ['commit-2-branch-1', 'commit-2-branch-2']
Changed Files: ['commit-2/file-1', 'commit-2/file-2']
Changed Files Stats:
commit-2/file-1: 5 additions, 8 deletions
commit-2/file-2: 7 additions, 9 deletions
{changed_files_stats2}
-----------------------
DEBUG: gitlint.git ('log', '4da2656b0dadc76c7ee3fd0243a96cb64007f125', '-1', '--pretty=%aN%x00%aE%x00%ai%x00%P%n%B')
DEBUG: gitlint.lint Linting commit 4da2656b0dadc76c7ee3fd0243a96cb64007f125
@ -135,7 +134,6 @@ Parents: ['c123']
Branches: ['commit-3-branch-1', 'commit-3-branch-2']
Changed Files: ['commit-3/file-1', 'commit-3/file-2']
Changed Files Stats:
commit-3/file-1: 1 additions, 4 deletions
commit-3/file-2: 3 additions, 4 deletions
{changed_files_stats3}
-----------------------
DEBUG: gitlint.cli Exit Code = 6

View file

@ -4,7 +4,8 @@ DEBUG: gitlint.cli Python version: {python_version}
DEBUG: gitlint.cli Git version: git version 1.2.3
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]

View file

@ -0,0 +1,8 @@
Commit 6f29bf81a8:
3: B5 Body message is too short (12<20): "commït-body1"
Commit 25053ccec5:
3: B5 Body message is too short (12<20): "commït-body2"
Commit 4da2656b0d:
3: B5 Body message is too short (12<20): "commït-body3"

View file

@ -4,7 +4,8 @@ DEBUG: gitlint.cli Python version: {python_version}
DEBUG: gitlint.cli Git version: git version 1.2.3
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]
@ -87,7 +88,6 @@ Parents: []
Branches: ['my-branch']
Changed Files: ['commit-1/file-1', 'commit-1/file-2']
Changed Files Stats:
commit-1/file-1: 3 additions, 4 deletions
commit-1/file-2: 4 additions, 7 deletions
{changed_files_stats}
-----------------------
DEBUG: gitlint.cli Exit Code = 2

View file

@ -4,7 +4,8 @@ DEBUG: gitlint.cli Python version: {python_version}
DEBUG: gitlint.cli Git version: git version 1.2.3
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]
@ -89,7 +90,6 @@ Parents: []
Branches: ['my-branch']
Changed Files: ['commit-1/file-1', 'commit-1/file-2']
Changed Files Stats:
commit-1/file-1: 1 additions, 5 deletions
commit-1/file-2: 8 additions, 9 deletions
{changed_files_stats}
-----------------------
DEBUG: gitlint.cli Exit Code = 3

View file

@ -4,7 +4,8 @@ DEBUG: gitlint.cli Python version: {python_version}
DEBUG: gitlint.cli Git version: git version 1.2.3
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: {config_path}
[GENERAL]

View file

@ -1,11 +1,15 @@
import os
from unittest.mock import call, patch
from unittest.mock import patch, call
from gitlint.shell import ErrorReturnCode, CommandNotFound
from gitlint.git import (
GitContext,
GitContextError,
GitNotInstalledError,
git_commentchar,
git_hooks_dir,
)
from gitlint.shell import CommandNotFound, ErrorReturnCode
from gitlint.tests.base import BaseTestCase
from gitlint.git import GitContext, GitContextError, GitNotInstalledError, git_commentchar, git_hooks_dir
class GitTests(BaseTestCase):

View file

@ -1,25 +1,21 @@
import copy
import datetime
from pathlib import Path
import dateutil
from unittest.mock import call, patch
import arrow
from unittest.mock import patch, call
from gitlint.tests.base import BaseTestCase
import dateutil
from gitlint.git import (
GitChangedFileStats,
GitContext,
GitCommit,
GitCommitMessage,
GitContext,
GitContextError,
LocalGitCommit,
StagedLocalGitCommit,
GitCommitMessage,
GitChangedFileStats,
)
from gitlint.shell import ErrorReturnCode
from gitlint.tests.base import BaseTestCase
class GitCommitTests(BaseTestCase):
@ -383,7 +379,7 @@ class GitCommitTests(BaseTestCase):
@patch("gitlint.git.sh")
def test_get_latest_commit_fixup_squash_commit(self, sh):
commit_prefixes = {"fixup": "is_fixup_commit", "squash": "is_squash_commit", "amend": "is_fixup_amend_commit"}
for commit_type in commit_prefixes.keys():
for commit_type in commit_prefixes:
sample_sha = "d8ac47e9f2923c7f22d8668e3a1ed04eb4cdbca9"
sh.git.side_effect = [
@ -616,7 +612,7 @@ class GitCommitTests(BaseTestCase):
# mapping between cleanup commit prefixes and the commit object attribute
commit_prefixes = {"fixup": "is_fixup_commit", "squash": "is_squash_commit", "amend": "is_fixup_amend_commit"}
for commit_type in commit_prefixes.keys():
for commit_type in commit_prefixes:
commit_msg = f"{commit_type}! Test message"
gitcontext = GitContext.from_commit_msg(commit_msg)
commit = gitcontext.commits[-1]
@ -642,7 +638,7 @@ class GitCommitTests(BaseTestCase):
@patch("gitlint.git.sh")
@patch("arrow.now")
def test_staged_commit(self, now, sh):
# StagedLocalGitCommit()
"""Test for StagedLocalGitCommit()"""
sh.git.side_effect = [
"#", # git config --get core.commentchar
@ -744,7 +740,7 @@ class GitCommitTests(BaseTestCase):
git.return_value = "foöbar"
# Test simple equality case
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
context1 = GitContext()
commit_message1 = GitCommitMessage(context1, "tëst\n\nfoo", "tëst\n\nfoo", "tēst", ["", "föo"])
commit1 = GitCommit(

View file

@ -1,7 +1,7 @@
from unittest.mock import patch, call
from unittest.mock import call, patch
from gitlint.tests.base import BaseTestCase
from gitlint.git import GitContext
from gitlint.tests.base import BaseTestCase
class GitContextTests(BaseTestCase):

View file

@ -1,5 +1,5 @@
from gitlint.tests.base import BaseTestCase
from gitlint import rules
from gitlint.tests.base import BaseTestCase
class BodyRuleTests(BaseTestCase):
@ -100,13 +100,13 @@ class BodyRuleTests(BaseTestCase):
expected_violation = rules.RuleViolation("B5", "Body message is too short (21<120)", "å" * 21, 3)
rule = rules.BodyMinLength({"min-length": 120})
commit = self.gitcommit("Title\n\n{}\n".format("å" * 21)) # pylint: disable=consider-using-f-string
commit = self.gitcommit("Title\n\n{}\n".format("å" * 21))
violations = rule.validate(commit)
self.assertListEqual(violations, [expected_violation])
# Make sure we don't get the error if the body-length is exactly the min-length
rule = rules.BodyMinLength({"min-length": 8})
commit = self.gitcommit("Tïtle\n\n{}\n".format("å" * 8)) # pylint: disable=consider-using-f-string
commit = self.gitcommit("Tïtle\n\n{}\n".format("å" * 8))
violations = rule.validate(commit)
self.assertIsNone(violations)

View file

@ -1,6 +1,9 @@
from gitlint.tests.base import BaseTestCase, EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING
from gitlint import rules
from gitlint.config import LintConfig
from gitlint.tests.base import (
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
BaseTestCase,
)
class ConfigurationRuleTests(BaseTestCase):
@ -89,6 +92,25 @@ class ConfigurationRuleTests(BaseTestCase):
self.assertEqual(config, LintConfig())
self.assert_logged([]) # nothing logged -> nothing ignored
# No author available -> rule is skipped and warning logged
staged_commit = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line")
rule = rules.IgnoreByAuthorName({"regex": "foo"})
config = LintConfig()
rule.apply(config, staged_commit)
self.assertEqual(config, LintConfig())
expected_log_messages = [
"WARNING: gitlint.rules ignore-by-author-name - I4: skipping - commit.author_name unknown. "
"Suggested fix: Use the --staged flag (or set general.staged=True in .gitlint). "
"More details: https://jorisroovers.com/gitlint/configuration/#staged"
]
self.assert_logged(expected_log_messages)
# Non-Matching regex -> expect config to stay the same
rule = rules.IgnoreByAuthorName({"regex": "foo"})
expected_config = LintConfig()
rule.apply(config, commit)
self.assertEqual(config, LintConfig())
# Matching regex -> expect config to ignore all rules
rule = rules.IgnoreByAuthorName({"regex": "(.*)ëst(.*)"})
expected_config = LintConfig()
@ -96,7 +118,7 @@ class ConfigurationRuleTests(BaseTestCase):
rule.apply(config, commit)
self.assertEqual(config, expected_config)
expected_log_messages = [
expected_log_messages += [
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I4", "ignore-by-author-name"),
"DEBUG: gitlint.rules Ignoring commit because of rule 'I4': "
"Commit Author Name 'Tëst nåme' matches the regex '(.*)ëst(.*)',"

View file

@ -1,5 +1,8 @@
from gitlint.tests.base import BaseTestCase, EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING
from gitlint.rules import AuthorValidEmail, RuleViolation
from gitlint.tests.base import (
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
BaseTestCase,
)
class MetaRuleTests(BaseTestCase):

View file

@ -1,8 +1,12 @@
from gitlint.tests.base import BaseTestCase
from gitlint.rules import Rule, RuleViolation
from gitlint.tests.base import BaseTestCase
class RuleTests(BaseTestCase):
def test_ruleviolation__str__(self):
expected = '57: rule-ïd Tēst message: "Tēst content"'
self.assertEqual(str(RuleViolation("rule-ïd", "Tēst message", "Tēst content", 57)), expected)
def test_rule_equality(self):
self.assertEqual(Rule(), Rule())
# Ensure rules are not equal if they differ on their attributes
@ -13,9 +17,16 @@ class RuleTests(BaseTestCase):
def test_rule_log(self):
rule = Rule()
self.assertIsNone(rule._log)
rule.log.debug("Tēst message")
self.assert_log_contains("DEBUG: gitlint.rules Tēst message")
# Assert the same logger is reused when logging multiple messages
log = rule._log
rule.log.debug("Anöther message")
self.assertEqual(log, rule._log)
self.assert_log_contains("DEBUG: gitlint.rules Anöther message")
def test_rule_violation_equality(self):
violation1 = RuleViolation("ïd1", "My messåge", "My cöntent", 1)
self.object_equality_test(violation1, ["rule_id", "message", "content", "line_nr"])

View file

@ -1,15 +1,15 @@
from gitlint.tests.base import BaseTestCase
from gitlint.rules import (
TitleMaxLength,
TitleTrailingWhitespace,
TitleHardTab,
TitleMustNotContainWord,
TitleTrailingPunctuation,
TitleLeadingWhitespace,
TitleRegexMatches,
RuleViolation,
TitleHardTab,
TitleLeadingWhitespace,
TitleMaxLength,
TitleMinLength,
TitleMustNotContainWord,
TitleRegexMatches,
TitleTrailingPunctuation,
TitleTrailingWhitespace,
)
from gitlint.tests.base import BaseTestCase
class TitleRuleTests(BaseTestCase):

View file

@ -1,11 +1,10 @@
import os
import sys
from gitlint.tests.base import BaseTestCase
from gitlint.rule_finder import find_rule_classes, assert_valid_rule_class
from gitlint.rules import UserRuleError
from gitlint import options, rules
from gitlint.rule_finder import assert_valid_rule_class, find_rule_classes
from gitlint.rules import UserRuleError
from gitlint.tests.base import BaseTestCase
class UserRuleTests(BaseTestCase):
@ -104,21 +103,21 @@ class UserRuleTests(BaseTestCase):
target = rules.CommitMessageTitle
def validate(self):
pass
pass # pragma: nocover
class MyCommitRuleClass(rules.CommitRule):
id = "UC2"
name = "my-cömmit-rule"
def validate(self):
pass
pass # pragma: nocover
class MyConfigurationRuleClass(rules.ConfigurationRule):
id = "UC3"
name = "my-cönfiguration-rule"
def apply(self):
pass
pass # pragma: nocover
# Just assert that no error is raised
self.assertIsNone(assert_valid_rule_class(MyLineRuleClass))
@ -203,7 +202,7 @@ class UserRuleTests(BaseTestCase):
assert_valid_rule_class(MyRuleClass)
# option_spec is a list, but not of gitlint options
MyRuleClass.options_spec = ["föo", 123] # pylint: disable=bad-option-value,redefined-variable-type
MyRuleClass.options_spec = ["föo", 123]
with self.assertRaisesMessage(UserRuleError, expected_msg):
assert_valid_rule_class(MyRuleClass)
@ -236,8 +235,8 @@ class UserRuleTests(BaseTestCase):
with self.assertRaisesMessage(UserRuleError, expected_msg):
assert_valid_rule_class(MyRuleClass)
# validate attribute - not a method
MyRuleClass.validate = "föo"
# apply attribute - not a method
MyRuleClass.apply = "föo"
with self.assertRaisesMessage(UserRuleError, expected_msg):
assert_valid_rule_class(MyRuleClass)
@ -247,7 +246,7 @@ class UserRuleTests(BaseTestCase):
name = "my-rüle-class"
def validate(self):
pass
pass # pragma: nocover
# no target
expected_msg = (
@ -263,5 +262,5 @@ class UserRuleTests(BaseTestCase):
assert_valid_rule_class(MyRuleClass)
# valid target, no exception should be raised
MyRuleClass.target = rules.CommitMessageTitle # pylint: disable=bad-option-value,redefined-variable-type
MyRuleClass.target = rules.CommitMessageTitle
self.assertIsNone(assert_valid_rule_class(MyRuleClass))

View file

@ -1,5 +1,5 @@
from gitlint.rules import CommitRule, RuleViolation
from gitlint.options import IntOption
from gitlint.rules import CommitRule, RuleViolation
class MyUserCommitRule(CommitRule):
@ -19,7 +19,7 @@ class MyUserCommitRule(CommitRule):
def func_should_be_ignored():
pass
pass # pragma: nocover
global_variable_should_be_ignored = True

View file

@ -9,4 +9,4 @@ class InitFileRule(CommitRule):
options_spec = []
def validate(self, _commit):
return []
return [] # pragma: nocover

View file

@ -1,5 +1,5 @@
from gitlint.tests.base import BaseTestCase
from gitlint.cache import PropertyCache, cache
from gitlint.tests.base import BaseTestCase
class CacheTests(BaseTestCase):

View file

@ -1,7 +1,10 @@
from gitlint.config import LintConfig
from gitlint.deprecation import Deprecation
from gitlint.rules import IgnoreByTitle
from gitlint.tests.base import EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING, BaseTestCase
from gitlint.tests.base import (
EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING,
BaseTestCase,
)
class DeprecationTests(BaseTestCase):

View file

@ -1,9 +1,8 @@
from io import StringIO
from unittest.mock import patch
from unittest.mock import patch # pylint: disable=no-name-in-module, import-error
from gitlint.display import Display
from gitlint.config import LintConfig
from gitlint.display import Display
from gitlint.tests.base import BaseTestCase

View file

@ -1,16 +1,15 @@
import os
from unittest.mock import ANY, mock_open, patch
from unittest.mock import patch, ANY, mock_open
from gitlint.tests.base import BaseTestCase
from gitlint.config import LintConfig
from gitlint.hooks import (
COMMIT_MSG_HOOK_DST_PATH,
COMMIT_MSG_HOOK_SRC_PATH,
GITLINT_HOOK_IDENTIFIER,
GitHookInstaller,
GitHookInstallerError,
COMMIT_MSG_HOOK_SRC_PATH,
COMMIT_MSG_HOOK_DST_PATH,
GITLINT_HOOK_IDENTIFIER,
)
from gitlint.tests.base import BaseTestCase
class HookTests(BaseTestCase):
@ -58,9 +57,10 @@ class HookTests(BaseTestCase):
expected_msg = f"{lint_config.target} is not a git repository."
with self.assertRaisesMessage(GitHookInstallerError, expected_msg):
GitHookInstaller.install_commit_msg_hook(lint_config)
isdir.assert_called_with(git_hooks_dir.return_value)
path_exists.assert_not_called()
copy.assert_not_called()
isdir.assert_called_with(git_hooks_dir.return_value)
path_exists.assert_not_called()
copy.assert_not_called()
# mock that there is already a commit hook present
isdir.return_value = True
@ -106,9 +106,10 @@ class HookTests(BaseTestCase):
expected_msg = f"{lint_config.target} is not a git repository."
with self.assertRaisesMessage(GitHookInstallerError, expected_msg):
GitHookInstaller.uninstall_commit_msg_hook(lint_config)
isdir.assert_called_with(git_hooks_dir.return_value)
path_exists.assert_not_called()
remove.assert_not_called()
isdir.assert_called_with(git_hooks_dir.return_value)
path_exists.assert_not_called()
remove.assert_not_called()
# mock that there is no commit hook present
isdir.return_value = True
@ -117,9 +118,10 @@ class HookTests(BaseTestCase):
expected_msg = f"There is no commit-msg hook present in {expected_dst}."
with self.assertRaisesMessage(GitHookInstallerError, expected_msg):
GitHookInstaller.uninstall_commit_msg_hook(lint_config)
isdir.assert_called_with(git_hooks_dir.return_value)
path_exists.assert_called_once_with(expected_dst)
remove.assert_not_called()
isdir.assert_called_with(git_hooks_dir.return_value)
path_exists.assert_called_once_with(expected_dst)
remove.assert_not_called()
# mock that there is a different (=not gitlint) commit hook
isdir.return_value = True

View file

@ -1,11 +1,10 @@
from io import StringIO
from unittest.mock import patch
from unittest.mock import patch # pylint: disable=no-name-in-module, import-error
from gitlint.tests.base import BaseTestCase
from gitlint.config import LintConfig, LintConfigBuilder
from gitlint.lint import GitLinter
from gitlint.rules import RuleViolation, TitleMustNotContainWord
from gitlint.config import LintConfig, LintConfigBuilder
from gitlint.tests.base import BaseTestCase
class LintTests(BaseTestCase):

View file

@ -1,12 +1,23 @@
import os
import re
from gitlint.options import (
BoolOption,
IntOption,
ListOption,
PathOption,
RegexOption,
RuleOptionError,
StrOption,
)
from gitlint.tests.base import BaseTestCase
from gitlint.options import IntOption, BoolOption, StrOption, ListOption, PathOption, RegexOption, RuleOptionError
class RuleOptionTests(BaseTestCase):
def test_option__str__(self):
option = StrOption("tëst-option", "åbc", "Test Dëscription")
self.assertEqual(str(option), "(tëst-option: åbc (Test Dëscription))")
def test_option_equality(self):
options = {
IntOption: 123,
@ -158,7 +169,7 @@ class RuleOptionTests(BaseTestCase):
option = PathOption("tëst-directory", ".", "Tëst Description", type="dir")
self.assertEqual(option.name, "tëst-directory")
self.assertEqual(option.description, "Tëst Description")
self.assertEqual(option.value, os.getcwd())
self.assertEqual(option.value, os.path.realpath("."))
self.assertEqual(option.type, "dir")
# re-set value

View file

@ -27,7 +27,7 @@ class UtilsTests(BaseTestCase):
self.assertEqual(utils.use_sh_library(), False)
@patch("gitlint.utils.locale")
def test_default_encoding_non_windows(self, mocked_locale):
def test_terminal_encoding_non_windows(self, mocked_locale):
utils.PLATFORM_IS_WINDOWS = False
mocked_locale.getpreferredencoding.return_value = "foöbar"
self.assertEqual(utils.getpreferredencoding(), "foöbar")
@ -37,7 +37,7 @@ class UtilsTests(BaseTestCase):
self.assertEqual(utils.getpreferredencoding(), "UTF-8")
@patch("os.environ")
def test_default_encoding_windows(self, patched_env):
def test_terminal_encoding_windows(self, patched_env):
utils.PLATFORM_IS_WINDOWS = True
# Mock out os.environ
mock_env = {}

View file

@ -1,9 +1,7 @@
# pylint: disable=bad-option-value,unidiomatic-typecheck,undefined-variable,no-else-return
import codecs
import platform
import os
import locale
import os
import platform
# Note: While we can easily inline the logic related to the constants set in this module, we deliberately create
# small functions that encapsulate that logic as this enables easy unit testing. In particular, by creating functions
@ -40,30 +38,28 @@ def use_sh_library():
USE_SH_LIB = use_sh_library()
########################################################################################################################
# DEFAULT_ENCODING
# TERMINAL_ENCODING
# Encoding used for terminal encoding/decoding.
def getpreferredencoding():
"""Modified version of local.getpreferredencoding() that takes into account LC_ALL, LC_CTYPE, LANG env vars
on windows and falls back to UTF-8."""
fallback_encoding = "UTF-8"
default_encoding = locale.getpreferredencoding() or fallback_encoding
preferred_encoding = locale.getpreferredencoding() or fallback_encoding
# On Windows, we mimic git/linux by trying to read the LC_ALL, LC_CTYPE, LANG env vars manually
# (on Linux/MacOS the `getpreferredencoding()` call will take care of this).
# We fallback to UTF-8
if PLATFORM_IS_WINDOWS:
default_encoding = fallback_encoding
preferred_encoding = fallback_encoding
for env_var in ["LC_ALL", "LC_CTYPE", "LANG"]:
encoding = os.environ.get(env_var, False)
if encoding:
# Support dotted (C.UTF-8) and non-dotted (C or UTF-8) charsets:
# If encoding contains a dot: split and use second part, otherwise use everything
dot_index = encoding.find(".")
if dot_index != -1:
default_encoding = encoding[dot_index + 1 :]
else:
default_encoding = encoding
preferred_encoding = encoding[dot_index + 1 :] if dot_index != -1 else encoding
break
# We've determined what encoding the user *wants*, let's now check if it's actually a valid encoding on the
@ -71,11 +67,21 @@ def getpreferredencoding():
# This scenario is fairly common on Windows where git sets LC_CTYPE=C when invoking the commit-msg hook, which
# is not a valid encoding in Python on Windows.
try:
codecs.lookup(default_encoding) # pylint: disable=no-member
codecs.lookup(preferred_encoding)
except LookupError:
default_encoding = fallback_encoding
preferred_encoding = fallback_encoding
return default_encoding
return preferred_encoding
DEFAULT_ENCODING = getpreferredencoding()
TERMINAL_ENCODING = getpreferredencoding()
########################################################################################################################
# FILE_ENCODING
# Gitlint assumes UTF-8 encoding for all file operations:
# - reading/writing its own hook and config files
# - reading/writing git commit messages
# Git does have i18n.commitEncoding and i18n.logOutputEncoding options which we might want to take into account,
# but that's not supported today.
FILE_ENCODING = "UTF-8"

View file

@ -0,0 +1,71 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"
[project]
name = "gitlint-core"
dynamic = ["version", "urls"]
description = "Git commit message linter written in python, checks your commit messages for style."
readme = "README.md"
license = "MIT"
requires-python = ">=3.7"
authors = [{ name = "Joris Roovers" }]
keywords = [
"git",
"gitlint",
"lint", #
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
]
dependencies = [
"arrow>=1",
"Click>=8",
"importlib-metadata >= 1.0 ; python_version < \"3.8\"",
"sh>=1.13.0 ; sys_platform != \"win32\"",
]
[project.optional-dependencies]
trusted-deps = [
"arrow==1.2.3",
"Click==8.1.3",
"sh==1.14.3 ; sys_platform != \"win32\"",
]
[project.scripts]
gitlint = "gitlint.cli:cli"
[tool.hatch.version]
source = "vcs"
raw-options = { root = ".." }
[tool.hatch.build]
include = [
"/gitlint", #
]
exclude = [
"/gitlint/tests", #
]
[tool.hatch.metadata.hooks.vcs.urls]
Homepage = "https://jorisroovers.github.io/gitlint"
Documentation = "https://jorisroovers.github.io/gitlint"
Source = "https://github.com/jorisroovers/gitlint/tree/main/gitlint-core"
Changelog = "https://github.com/jorisroovers/gitlint/blob/main/CHANGELOG.md"
# TODO(jorisroovers): Temporary disable until fixed in hatch-vcs (see #460)
# 'Source Commit' = "https://github.com/jorisroovers/gitlint/tree/{commit_hash}/gitlint-core"

View file

@ -1,2 +0,0 @@
[bdist_wheel]
universal = 1

View file

@ -1,109 +0,0 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
import io
import re
import os
import platform
import sys
description = "Git commit message linter written in python, checks your commit messages for style."
long_description = """
Great for use as a commit-msg git hook or as part of your gating script in a CI pipeline (e.g. jenkins, github actions).
Many of the gitlint validations are based on `well-known`_ community_ `standards`_, others are based on checks that
we've found useful throughout the years. Gitlint has sane defaults, but you can also easily customize it to your
own liking.
Demo and full documentation on `jorisroovers.github.io/gitlint`_.
To see what's new in the latest release, visit the CHANGELOG_.
Source code on `github.com/jorisroovers/gitlint`_.
.. _well-known: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
.. _community: http://addamhardy.com/blog/2013/06/05/good-commit-messages-and-enforcing-them-with-git-hooks/
.. _standards: http://chris.beams.io/posts/git-commit/
.. _jorisroovers.github.io/gitlint: https://jorisroovers.github.io/gitlint
.. _CHANGELOG: https://github.com/jorisroovers/gitlint/blob/main/CHANGELOG.md
.. _github.com/jorisroovers/gitlint: https://github.com/jorisroovers/gitlint
"""
# shamelessly stolen from mkdocs' setup.py: https://github.com/mkdocs/mkdocs/blob/master/setup.py
def get_version(package):
"""Return package version as listed in `__version__` in `init.py`."""
init_py = open(os.path.join(package, "__init__.py"), encoding="UTF-8").read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
setup(
name="gitlint-core",
version=get_version("gitlint"),
description=description,
long_description=long_description,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Environment :: Console",
"Intended Audience :: Developers",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
"License :: OSI Approved :: MIT License",
],
python_requires=">=3.6",
install_requires=[
"Click>=8",
"arrow>=1",
'sh>=1.13.0 ; sys_platform != "win32"',
],
extras_require={
"trusted-deps": [
"Click==8.0.3",
"arrow==1.2.1",
'sh==1.14.2 ; sys_platform != "win32"',
],
},
keywords="gitlint git lint",
author="Joris Roovers",
url="https://jorisroovers.github.io/gitlint",
project_urls={
"Documentation": "https://jorisroovers.github.io/gitlint",
"Source": "https://github.com/jorisroovers/gitlint",
},
license="MIT",
package_data={"gitlint": ["files/*"]},
packages=find_packages(exclude=["examples"]),
entry_points={
"console_scripts": [
"gitlint = gitlint.cli:cli",
],
},
)
# Print a red deprecation warning for python < 3.6 users
if sys.version_info[:2] < (3, 6):
msg = (
"\033[31mDEPRECATION: You're using a python version that has reached end-of-life. "
+ "Gitlint does not support Python < 3.6"
+ "Please upgrade your Python to 3.6 or above.\033[0m"
)
print(msg)
# Print a warning message for Windows users
PLATFORM_IS_WINDOWS = "windows" in platform.system().lower()
if PLATFORM_IS_WINDOWS:
msg = (
"\n\n\n\n\n****************\n"
+ "WARNING: Gitlint support for Windows is still experimental and there are some known issues: "
+ "https://github.com/jorisroovers/gitlint/issues?q=is%3Aissue+is%3Aopen+label%3Awindows "
+ "\n*******************"
)
print(msg)

13
hatch_build.py Normal file
View file

@ -0,0 +1,13 @@
# hatch_build.py is executed by hatch at build-time and can contain custom build logic hooks
import os
from hatchling.metadata.plugin.interface import MetadataHookInterface
class CustomMetadataHook(MetadataHookInterface):
"""Custom metadata hook for hatch that ensures that gitlint and gitlint-core[trusted-deps] versions always match"""
def update(self, metadata: dict) -> None:
# Only enforce versioning matching outside of the 'dev' environment, this allows for re-use of the 'dev'
# environment between different git branches.
if os.environ.get("HATCH_ENV_ACTIVE", "not-dev") != "dev":
metadata["dependencies"] = [f"gitlint-core[trusted-deps]=={metadata['version']}"]

View file

@ -1,5 +1,203 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"
[project]
name = "gitlint"
dynamic = ["version", "dependencies", "urls"]
description = "Git commit message linter written in python, checks your commit messages for style."
readme = "README.md"
license = "MIT"
requires-python = ">=3.7"
authors = [{ name = "Joris Roovers" }]
keywords = [
"git",
"gitlint",
"lint", #
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
]
[tool.hatch.version]
source = "vcs"
[tool.hatch.build]
exclude = ["*"]
[tool.hatch.metadata.hooks.vcs.urls]
Homepage = "https://jorisroovers.github.io/gitlint"
Documentation = "https://jorisroovers.github.io/gitlint"
Source = "https://github.com/jorisroovers/gitlint"
Changelog = "https://github.com/jorisroovers/gitlint/blob/main/CHANGELOG.md"
# TODO(jorisroovers): Temporary disable until fixed in hatch-vcs (see #460)
# 'Source Archive' = "https://github.com/jorisroovers/gitlint/archive/{commit_hash}.zip"
# 'Source Commit' = "https://github.com/jorisroovers/gitlint/tree/{commit_hash}"
# Use metadata hooks specified in 'hatch_build.py'
# (this line is critical when building wheels, when building sdist it seems optional)
[tool.hatch.metadata.hooks.custom]
# Environments #########################################################################################################
# NOTE: By default all environments inherit from the 'default' environment
# DEV
# Workaround for editable install:
# https://github.com/pypa/hatch/issues/588
[tool.hatch.envs.dev]
description = """
Dev environment (running gitlint itself from source)
"""
pre-install-commands = [
"pip install -e ./gitlint-core", #
]
[tool.hatch.envs.dev.scripts]
fullclean = [
"rm .coverage .coverage.lcov",
"rm -rf site dist .pytest_cache",
"rm -rf gitlint-core/dist gitlint-core/build gitlint-core/.pytest_cache",
"rm -rf qa/__pycache__ qa/.pytest_cache",
]
# TEST
[tool.hatch.envs.test]
description = """
Test environment (unit tests, formatting, lint)
"""
skip-install = true
dependencies = [
"gitlint-core[trusted-deps] @ {root:uri}/gitlint-core",
"black==23.1.0",
"pytest==7.2.1",
"pytest-cov==4.0.0",
"python-coveralls==2.9.3",
"ruff==0.0.252",
"radon==5.1.0",
"pdbr==0.8.2; sys_platform != \"win32\"",
]
[tool.hatch.envs.test.scripts]
unit-tests = [
"pytest --cov=gitlint-core --cov-report=term --cov-report=lcov:.coverage.lcov -rw -s {args:gitlint-core}",
]
u = "unit-tests"
unit-tests-no-cov = "pytest -rw -s {args:gitlint-core}"
format = "black --check --diff {args:.}"
lint = "ruff {args:gitlint-core/gitlint qa}"
autoformat = "black {args:.}"
autofix = [
"ruff --fix {args:gitlint-core/gitlint qa}",
"autoformat", #
]
all = [
"unit-tests",
"format",
"lint", #
]
stats = ["./tools/stats.sh"]
# QA
[tool.hatch.envs.qa]
description = """
Integration test environment.
Run a set of integration tests against any gitlint binary (not just the one from local source).
"""
detached = true
dependencies = [
"pytest==7.2.1",
"arrow==1.2.3",
"sh==1.14.3; sys_platform != \"win32\"",
"pdbr==0.8.2; sys_platform != \"win32\"",
]
[tool.hatch.envs.qa.scripts]
# The integration tests can be ran against any gitlint binary, e.g. one installed from pypi (for post-release testing)
# This is why by default we don't install the local dev version of gitlint in the qa environment
# To run integration tests against the dev version of gitlint, use install-local first
install-local = "pip install -e ./gitlint-core[trusted-deps]"
integration-tests = "pytest -rw -s {args:qa}"
i = "integration-tests"
# DOCS
[tool.hatch.envs.docs]
description = """
Documentation environment. Run docs build and serve commands.
"""
detached = true
dependencies = [
"mkdocs==1.4.2", #
]
[tool.hatch.envs.docs.scripts]
build = "mkdocs build --clean --strict"
serve = "mkdocs serve"
# Tool config ##########################################################################################################
[tool.black]
target_version = ['py36', 'py37', 'py38','py39','py310']
target_version = ['py37', 'py38', 'py39', 'py310']
line-length = 120
# extend-exclude: keep excluding files from .gitignore in addition to the ones specified
extend-exclude = "gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py"
extend-exclude = "gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py"
[tool.ruff]
target-version = "py37"
extend-exclude = [
"gitlint-core/gitlint/tests/samples/user_rules/import_exception/invalid_python.py",
]
ignore = [
"E501", # Never enforce `E501` (line length violations) - taken care of by black
"SIM108", # Use ternary operator instead of if-else-block
"PLR0913", # Too many arguments to function call
]
select = [
"F", # PyFlakes
"E", # Pycodestyle
"W", # Pycodestyle
"I", # isort (import order)
"YTT", # flake8-2020 (misuse of sys.version)
"S", # flake8-bandit (security)
"B", # flake8-bugbear
"C4", # flake8-comprehensions (correct use of comprehensions)
"T10", # flake8-debugger (no debug statements)
"T20", # flake8-print (no print statements)
"SIM", # flake8-simplify (use simple code)
"TID", # flake8-tidy-imports (correct import syntax)
"ARG", # flake8-unused-arguments (no unused function arguments)
"DTZ", # flake8-datetimez (correct datetime usage)
"ERA", # eradicate (no commented out code)
"UP", # pyupgrade (modern python syntax)
"PLC", # pylint
"PLE", # pylint
"PLR", # pylint
"PLW", # pylint
"PIE", # flake8-pie
"RUF", # ruff specific
]
[tool.coverage.run]
branch = true # measure branch coverage in addition to statement coverage
[tool.coverage.report]
fail_under = 97
show_missing = true

View file

@ -1,20 +1,16 @@
# pylint: disable=bad-option-value,unidiomatic-typecheck,undefined-variable,no-else-return,
# pylint: disable=too-many-function-args,unexpected-keyword-arg
import os
import platform
import shutil
import sys
import tempfile
from datetime import datetime
from uuid import uuid4
from datetime import datetime, timezone
from unittest import TestCase
from uuid import uuid4
import arrow
from qa.shell import git, gitlint, RunningCommand
from qa.utils import DEFAULT_ENCODING
from qa.shell import RunningCommand, git, gitlint
from qa.utils import FILE_ENCODING, PLATFORM_IS_WINDOWS, TERMINAL_ENCODING
class BaseTestCase(TestCase):
@ -40,18 +36,19 @@ class BaseTestCase(TestCase):
for tmpfile in self.tmpfiles:
os.remove(tmpfile)
for repo in self.tmp_git_repos:
shutil.rmtree(repo)
# On windows we need to ignore errors because git might still be holding on to some files
shutil.rmtree(repo, ignore_errors=PLATFORM_IS_WINDOWS)
def assertEqualStdout(self, output, expected): # pylint: disable=invalid-name
def assertEqualStdout(self, output, expected):
self.assertIsInstance(output, RunningCommand)
output = output.stdout.decode(DEFAULT_ENCODING)
output = output.stdout.decode(TERMINAL_ENCODING)
output = output.replace("\r", "")
self.assertMultiLineEqual(output, expected)
@staticmethod
def generate_temp_path():
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
return os.path.realpath(f"/tmp/gitlint-test-{timestamp}")
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d-%H%M%S-%f")
return os.path.realpath(f"/tmp/gitlint-test-{timestamp}") # noqa
def create_tmp_git_repo(self):
"""Creates a temporary git repository and returns its directory path"""
@ -72,6 +69,9 @@ class BaseTestCase(TestCase):
# http://stackoverflow.com/questions/5581857/git-and-the-umlaut-problem-on-mac-os-x
git("config", "core.precomposeunicode", "true", _cwd=tmp_git_repo)
# Git now does commit message cleanup by default (e.g. removing trailing whitespace), disable that for testing
git("config", "commit.cleanup", "verbatim", _cwd=tmp_git_repo)
return tmp_git_repo
@staticmethod
@ -84,13 +84,12 @@ class BaseTestCase(TestCase):
if isinstance(content, bytes):
open_kwargs = {"mode": "wb"}
else:
open_kwargs = {"mode": "w", "encoding": DEFAULT_ENCODING}
open_kwargs = {"mode": "w", "encoding": FILE_ENCODING}
with open(full_path, **open_kwargs) as f: # pylint: disable=unspecified-encoding
with open(full_path, **open_kwargs) as f:
f.write(content)
else:
# pylint: disable=consider-using-with
open(full_path, "a", encoding=DEFAULT_ENCODING).close()
open(full_path, "a", encoding=FILE_ENCODING).close() # noqa: SIM115 (Use context handler for opening files)
return test_filename
@ -150,9 +149,9 @@ class BaseTestCase(TestCase):
if isinstance(content, bytes):
open_kwargs = {"mode": "wb"}
else:
open_kwargs = {"mode": "w", "encoding": DEFAULT_ENCODING}
open_kwargs = {"mode": "w", "encoding": FILE_ENCODING}
with open(tmpfile, **open_kwargs) as f: # pylint: disable=unspecified-encoding
with open(tmpfile, **open_kwargs) as f:
f.write(content)
return tmpfilepath
@ -181,7 +180,8 @@ class BaseTestCase(TestCase):
specified by variable_dict."""
expected_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "expected")
expected_path = os.path.join(expected_dir, filename)
with open(expected_path, encoding=DEFAULT_ENCODING) as file:
# Expected files are UTF-8 encoded (not dependent on the system's default encoding)
with open(expected_path, encoding=FILE_ENCODING) as file:
expected = file.read()
if variable_dict:
@ -199,7 +199,8 @@ class BaseTestCase(TestCase):
"git_version": expected_git_version,
"gitlint_version": expected_gitlint_version,
"GITLINT_USE_SH_LIB": BaseTestCase.GITLINT_USE_SH_LIB,
"DEFAULT_ENCODING": DEFAULT_ENCODING,
"TERMINAL_ENCODING": TERMINAL_ENCODING,
"FILE_ENCODING": FILE_ENCODING,
}
def get_debug_vars_last_commit(self, git_repo=None):

View file

@ -5,7 +5,8 @@ DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: {git_version}
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]

View file

@ -5,7 +5,8 @@ DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: {git_version}
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]

View file

@ -5,7 +5,8 @@ DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: {git_version}
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]

View file

@ -5,7 +5,8 @@ DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: {git_version}
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]

View file

@ -5,7 +5,8 @@ DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: {git_version}
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: {config_path}
[GENERAL]

View file

@ -5,7 +5,8 @@ DEBUG: gitlint.git ('--version',)
DEBUG: gitlint.cli Git version: {git_version}
DEBUG: gitlint.cli Gitlint version: {gitlint_version}
DEBUG: gitlint.cli GITLINT_USE_SH_LIB: {GITLINT_USE_SH_LIB}
DEBUG: gitlint.cli DEFAULT_ENCODING: {DEFAULT_ENCODING}
DEBUG: gitlint.cli TERMINAL_ENCODING: {TERMINAL_ENCODING}
DEBUG: gitlint.cli FILE_ENCODING: {FILE_ENCODING}
DEBUG: gitlint.cli Configuration
config-path: None
[GENERAL]

View file

@ -0,0 +1,3 @@
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: Commït Tïtle"
3: B3 Line contains hard tab characters (\t): "Sïmple commit body"
4: B2 Line has trailing whitespace: "Anōther Line "

View file

@ -0,0 +1,2 @@
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: Commït Tïtle"
3: B3 Line contains hard tab characters (\t): "Sïmple commit body"

View file

@ -0,0 +1,2 @@
1: T7 Title does not match regex (foo): "Thåt dûr bår"
4: B8 Body does not match regex (bar)

View file

@ -2,3 +2,4 @@
1: UC3 Branch name 'main' does not start with one of ['feature/', 'hotfix/', 'release/']
1: UL1 Title contains the special character '$'
2: B4 Second line is not empty
3: B3 Line contains hard tab characters (\t)

View file

@ -1,4 +0,0 @@
sh==1.14.3
pytest==7.0.1;
arrow==1.2.3;
gitlint # no version as you want to test the currently installed version

View file

@ -1,5 +1,5 @@
from gitlint.rules import CommitRule, RuleViolation, ConfigurationRule
from gitlint.options import IntOption, StrOption, ListOption
from gitlint.options import IntOption, ListOption, StrOption
from gitlint.rules import CommitRule, ConfigurationRule, RuleViolation
class GitContextRule(CommitRule):
@ -64,9 +64,9 @@ class ConfigurableCommitRule(CommitRule):
def validate(self, _):
violations = [
RuleViolation(self.id, f"int-öption: {self.options[u'int-öption'].value}", line_nr=1),
RuleViolation(self.id, f"str-öption: {self.options[u'str-öption'].value}", line_nr=1),
RuleViolation(self.id, f"list-öption: {self.options[u'list-öption'].value}", line_nr=1),
RuleViolation(self.id, f"int-öption: {self.options['int-öption'].value}", line_nr=1),
RuleViolation(self.id, f"str-öption: {self.options['str-öption'].value}", line_nr=1),
RuleViolation(self.id, f"list-öption: {self.options['list-öption'].value}", line_nr=1),
]
return violations

View file

@ -2,24 +2,31 @@
# on gitlint internals for our integration testing framework.
import subprocess
from qa.utils import USE_SH_LIB, DEFAULT_ENCODING
from qa.utils import TERMINAL_ENCODING, USE_SH_LIB
if USE_SH_LIB:
from sh import git, echo, gitlint # pylint: disable=unused-import,no-name-in-module,import-error
from sh import (
echo,
git,
gitlint,
)
gitlint = gitlint.bake(_unify_ttys=True, _tty_in=True) # pylint: disable=invalid-name
gitlint = gitlint.bake(_unify_ttys=True, _tty_in=True)
# import exceptions separately, this makes it a little easier to mock them out in the unit tests
from sh import CommandNotFound, ErrorReturnCode, RunningCommand # pylint: disable=import-error
from sh import (
CommandNotFound,
ErrorReturnCode,
RunningCommand,
)
else:
class CommandNotFound(Exception):
"""Exception indicating a command was not found during execution"""
pass
class RunningCommand:
pass
...
class ShResult(RunningCommand):
"""Result wrapper class. We use this to more easily migrate from using https://amoffat.github.io/sh/ to using
@ -29,18 +36,35 @@ else:
self.full_cmd = full_cmd
# TODO(jorisroovers): The 'sh' library by default will merge stdout and stderr. We mimic this behavior
# for now until we fully remove the 'sh' library.
self.stdout = stdout + stderr.decode(DEFAULT_ENCODING)
self.stderr = stderr
self._stdout = stdout + stderr
self._stderr = stderr
self.exit_code = exitcode
def __str__(self):
return self.stdout.decode(TERMINAL_ENCODING)
def __unicode__(self):
return self.stdout
@property
def stdout(self):
return self._stdout
@property
def stderr(self):
return self._stderr
def __getattr__(self, p):
# https://github.com/amoffat/sh/blob/e0ed8e244e9d973ef4e0749b2b3c2695e7b5255b/sh.py#L952=
_unicode_methods = set(dir(str())) # noqa
if p in _unicode_methods:
return getattr(str(self), p)
raise AttributeError
class ErrorReturnCode(ShResult, Exception):
"""ShResult subclass for unexpected results (acts as an exception)."""
pass
def git(*command_parts, **kwargs):
return run_command("git", *command_parts, **kwargs)
@ -51,31 +75,36 @@ else:
return run_command("gitlint", *command_parts, **kwargs)
def run_command(command, *args, **kwargs):
args = [command] + list(args)
result = _exec(*args, **kwargs)
# If we reach this point and the result has an exit_code that is larger than 0, this means that we didn't
# get an exception (which is the default sh behavior for non-zero exit codes) and so the user is expecting
# a non-zero exit code -> just return the entire result
if hasattr(result, "exit_code") and result.exit_code > 0:
return result
return str(result)
args = [command, *list(args)]
return _exec(*args, **kwargs)
def _exec(*args, **kwargs):
pipe = subprocess.PIPE
popen_kwargs = {"stdout": pipe, "stderr": pipe, "shell": kwargs.get("_tty_out", False)}
if "_cwd" in kwargs:
popen_kwargs["cwd"] = kwargs["_cwd"]
if "_env" in kwargs:
popen_kwargs["env"] = kwargs["_env"]
popen_kwargs = {
"stdout": subprocess.PIPE,
"stderr": subprocess.PIPE,
"stdin": subprocess.PIPE,
"shell": kwargs.get("_tty_out", False),
"cwd": kwargs.get("_cwd", None),
"env": kwargs.get("_env", None),
}
stdin_input = None
if len(args) > 1 and isinstance(args[1], ShResult):
stdin_input = args[1].stdout
# pop args[1] from the array and use it as stdin
args = list(args)
args.pop(1)
popen_kwargs["stdin"] = subprocess.PIPE
try:
with subprocess.Popen(args, **popen_kwargs) as p:
result = p.communicate()
result = p.communicate(stdin_input)
except FileNotFoundError as exc:
raise CommandNotFound from exc
exit_code = p.returncode
stdout = result[0].decode(DEFAULT_ENCODING)
stdout = result[0]
stderr = result[1] # 'sh' does not decode the stderr bytes to unicode
full_cmd = "" if args is None else " ".join(args)

View file

@ -1,10 +1,9 @@
# pylint: disable=too-many-function-args,unexpected-keyword-arg
import re
import arrow
from qa.shell import echo, git, gitlint
from qa.base import BaseTestCase
from qa.shell import echo, git, gitlint
class CommitsTests(BaseTestCase):
@ -111,6 +110,11 @@ class CommitsTests(BaseTestCase):
self.assertEqual(output.exit_code, 2)
self.assertEqualStdout(output, expected)
# Lint using --commits <commit sha>,
output = gitlint("--commits", f"{commit_sha},", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
self.assertEqual(output.exit_code, 2)
self.assertEqualStdout(output, expected)
# Lint a single commit using --commits <refspec> pointing to the single commit
output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
self.assertEqual(output.exit_code, 2)
@ -129,7 +133,7 @@ class CommitsTests(BaseTestCase):
self.assertEqual(output.exit_code, 254)
def test_lint_staged_stdin(self):
"""Tests linting a staged commit. Gitint should lint the passed commit message andfetch additional meta-data
"""Tests linting a staged commit. Gitint should lint the passed commit message and fetch additional meta-data
from the underlying repository. The easiest way to test this is by inspecting `--debug` output.
This is the equivalent of doing:
echo "WIP: Pïpe test." | gitlint --staged --debug

View file

@ -1,10 +1,8 @@
# pylint: disable=too-many-function-args,unexpected-keyword-arg
import os
import re
from qa.shell import gitlint
from qa.base import BaseTestCase
from qa.utils import DEFAULT_ENCODING
from qa.shell import gitlint
class ConfigTests(BaseTestCase):
@ -69,7 +67,7 @@ class ConfigTests(BaseTestCase):
"This line of the body is here because we need it"
)
filename = self.create_simple_commit(commit_msg, git_repo=target_repo)
config_path = self.get_sample_path("config/gitlintconfig")
config_path = self.get_sample_path(os.path.join("config", "gitlintconfig"))
output = gitlint("--config", config_path, "--debug", _cwd=target_repo, _tty_in=True, _ok_code=[5])
expected_kwargs = self.get_debug_vars_last_commit(git_repo=target_repo)
@ -128,7 +126,7 @@ class ConfigTests(BaseTestCase):
# Extract date from actual output to insert it into the expected output
# We have to do this since there's no way for us to deterministically know that date otherwise
p = re.compile("Date: (.*)\n", re.UNICODE | re.MULTILINE)
result = p.search(output.stdout.decode(DEFAULT_ENCODING))
result = p.search(str(output))
date = result.group(1).strip()
expected_kwargs.update({"date": date})

View file

@ -1,6 +1,5 @@
# pylint: disable=
from qa.shell import gitlint
from qa.base import BaseTestCase
from qa.shell import gitlint
class ContribRuleTests(BaseTestCase):

View file

@ -1,8 +1,8 @@
# pylint: disable=too-many-function-args,unexpected-keyword-arg
import os
from qa.shell import echo, git, gitlint
from qa.base import BaseTestCase
from qa.utils import DEFAULT_ENCODING
from qa.shell import echo, git, gitlint
from qa.utils import FILE_ENCODING
class IntegrationTests(BaseTestCase):
@ -58,7 +58,7 @@ class IntegrationTests(BaseTestCase):
self.assertEqualStdout(output, expected)
# Make a small modification to the commit and commit it using fixup commit
with open(os.path.join(self.tmp_git_repo, test_filename), "a", encoding=DEFAULT_ENCODING) as fh:
with open(os.path.join(self.tmp_git_repo, test_filename), "a", encoding=FILE_ENCODING) as fh:
fh.write("Appending söme stuff\n")
git("add", test_filename, _cwd=self.tmp_git_repo)
@ -87,7 +87,7 @@ class IntegrationTests(BaseTestCase):
self.assertEqualStdout(output, expected)
# Make a small modification to the commit and commit it using fixup=amend commit
with open(os.path.join(self.tmp_git_repo, test_filename), "a", encoding=DEFAULT_ENCODING) as fh:
with open(os.path.join(self.tmp_git_repo, test_filename), "a", encoding=FILE_ENCODING) as fh:
fh.write("Appending söme stuff\n")
git("add", test_filename, _cwd=self.tmp_git_repo)
@ -133,7 +133,7 @@ class IntegrationTests(BaseTestCase):
self.assertEqualStdout(output, expected)
# Make a small modification to the commit and commit it using squash commit
with open(os.path.join(self.tmp_git_repo, test_filename), "a", encoding=DEFAULT_ENCODING) as fh:
with open(os.path.join(self.tmp_git_repo, test_filename), "a", encoding=FILE_ENCODING) as fh:
# Wanted to write a unicode string, but that's obnoxious if you want to do it across Python 2 and 3.
# https://stackoverflow.com/questions/22392377/
# error-writing-a-file-with-file-write-in-python-unicodeencodeerror
@ -252,7 +252,7 @@ class IntegrationTests(BaseTestCase):
binary_filename = self.create_simple_commit("Sïmple commit", file_contents=bytes([0x48, 0x00, 0x49, 0x00]))
output = gitlint(
"--debug",
_ok_code=1,
_ok_code=[1],
_cwd=self.tmp_git_repo,
)

Some files were not shown because too many files have changed in this diff Show more