LinuxCommandLibrary

core-validate-commit

Validate Linux kernel commit message and code

TLDR

Validate the current commit

$ core-validate-commit
copy

Validate a specific commit
$ core-validate-commit [commit_hash]
copy

Validate a range of commits
$ git rev-list [commit_hash]..HEAD | xargs core-validate-commit
copy

List all validation rules
$ core-validate-commit --list
copy

List all valid Node.js subsystems
$ core-validate-commit --list-subsystem
copy

Validate the current commit formatting the output in tap format
$ core-validate-commit --tap
copy

Display help
$ core-validate-commit --help
copy

SYNOPSIS

`core-validate-commit [-s|-a] []`

PARAMETERS

-s
    Check a Staged commit message.

-a
    Check a Amend commit message.

[]
    Specify the commit to validate (defaults to HEAD).

DESCRIPTION

The `core-validate-commit` script is used to check if a commit message conforms to the Linux kernel's coding style and conventions. It's typically part of the kernel's development workflow, ensuring consistency and readability of commit history. This script examines the commit message header and body, looking for issues such as line length violations, proper subject line formatting, blank lines, and accurate tag usage.

It helps maintain a clean and informative commit log, which is essential for debugging, auditing, and understanding the kernel's evolution. By enforcing these standards, it improves the overall quality and maintainability of the Linux kernel codebase.

When issues are found, the script outputs messages indicating the specific violations. Developers use this feedback to revise their commit messages before submitting patches. The script runs many different git commands behind the scene to find the commit message which needs to be validated. The correct formating of commit messages can aid tools like `git bisect` or `git blame`. The `git config` option `commit.verbose` can also aid in formating correct commit messages.

CAVEATS

The script relies on specific git configuration and environment variables to function correctly. Ensure that the script is executed within a valid Linux kernel source tree. Without specified parameter, it checks the commit message for the most recent commit (HEAD).

COMMIT MESSAGE CONVENTIONS

The Linux kernel has specific rules for commit messages, including the 50/72 rule (subject line should be no more than 50 characters, lines in the body should be wrapped at 72 characters), use of imperative mood in the subject line, and inclusion of detailed explanations in the body. This script automates checking for these rules.
Example of subject line: fix: Fix memory leak in foobar driver

HISTORY

The `core-validate-commit` script evolved alongside the Linux kernel's development practices. As the kernel grew in complexity, the need for standardized commit messages became crucial. It was introduced as part of the kernel's development tooling to help enforce these standards, contributing to a more organized and understandable project history. Initially, the validation might have been simpler, but as the kernel's rules became more refined, so did the script's capabilities to ensure accurate formatting.

SEE ALSO

Copied to clipboard