Skip to content

Failures are ignored if subsequent checks pass in single run #212

@B-McDonnell

Description

@B-McDonnell

describe your issue

When commit-check is run with multiple checks, failures are overridden by passing checks that run after the failures.

Example running only --message, which fails as expected:

hooks/commit-msg:

#!/bin/sh

MESSAGE_FILE="$1"

# check message only
commit-check --message "$MESSAGE_FILE"

example commit:

git commit -m "unconventional commit with a bad message!"
Commit rejected by Commit-Check.

  (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)
   / ._. \      / ._. \      / ._. \      / ._. \      / ._. \
 __\( C )/__  __\( H )/__  __\( E )/__  __\( C )/__  __\( K )/__
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
   || E ||      || R ||      || R ||      || O ||      || R ||
 _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
 `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´

Commit rejected.

Type message check failed => unconventional commit with a bad message!

It doesn't match regex: ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)
The commit message should be structured as follows:

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

More details please refer to https://www.conventionalcommits.org
Suggest: please check your commit message whether matches above regex

git log:

72b8ebc (HEAD -> main) feat: Initial commit

Example running both --message and --author-name (with name set in git config) which succeeds unexpectedly:

hooks/commit-msg:

#!/bin/sh

MESSAGE_FILE="$1"

# check message and author name
commit-check --message --author-name "$MESSAGE_FILE"

Example commit:

$ git commit -m "unconventional commit with a bad message!"
Commit rejected by Commit-Check.

  (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)    (c).-.(c)
   / ._. \      / ._. \      / ._. \      / ._. \      / ._. \
 __\( C )/__  __\( H )/__  __\( E )/__  __\( C )/__  __\( K )/__
(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
   || E ||      || R ||      || R ||      || O ||      || R ||
 _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._  _.' '-' '._
(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)
 `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´  `-´     `-´

Commit rejected.

Type message check failed => unconventional commit with a bad message!

It doesn't match regex: ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)|(Merge).*|(fixup!.*)
The commit message should be structured as follows:

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

More details please refer to https://www.conventionalcommits.org
Suggest: please check your commit message whether matches above regex

[main 3601b27] unconventional commit with a bad message!
 1 file changed, 4 insertions(+)
 create mode 100755 hooks/pre-commit

git log:

3601b27 (HEAD -> main) unconventional commit with a bad message!
72b8ebc feat: Initial commit

Cause

The source of the bug is here: https://github.com/commit-check/commit-check/blame/91ee12b3f5045523cbdacd07390c0ce98f3b8231/commit_check/main.py#L109-L124

Annotated with previous example:

def main() -> int:
    """The main entrypoint of commit-check program."""
    parser = get_parser()
    args = parser.parse_args()
    retval = PASS

    with error_handler():
        config = validate_config(args.config) if validate_config(
            args.config,
        ) else DEFAULT_CONFIG
        checks = config['checks']
        if args.message:
            retval = commit.check_commit_msg(checks, args.commit_msg_file)  # retval is now FAIL
        if args.author_name:
            retval = author.check_author(checks, "author_name")             # retval is now PASS! Uh oh!
        if args.author_email:
            retval = author.check_author(checks, "author_email")
        if args.branch:
            retval = branch.check_branch(checks)
        if args.commit_signoff:
            retval = commit.check_commit_signoff(checks)
        if args.merge_base:
            retval = branch.check_merge_base(checks)

    if args.dry_run:
        retval = PASS
    return retval  # returns PASS

commit-check version

commit-check 0.9.2

.commit-check.yml

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions