As always we need a working it repository with the hooks installed to run these lints
git init .
git mit-install
I'm going to assume you've run a git mit
recently
git mit bt
You can see the full available lint list at any time by running
git mit-config lint available
╭───────────────────────────────────┬──────────╮
│ Lint ┆ Status │
╞═══════════════════════════════════╪══════════╡
│ duplicated-trailers ┆ enabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ pivotal-tracker-id-missing ┆ disabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ jira-issue-key-missing ┆ disabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ github-id-missing ┆ disabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ subject-not-separated-from-body ┆ enabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ subject-longer-than-72-characters ┆ enabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ subject-line-not-capitalized ┆ disabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ subject-line-ends-with-period ┆ disabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ body-wider-than-72-characters ┆ enabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ not-conventional-commit ┆ disabled │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ not-emoji-log ┆ disabled │
╰───────────────────────────────────┴──────────╯
Lints relating to trailers:
Detect duplicated Signed-off-by
, Co-authored-by
, and Relates-to
Trailers.
On an empty repository
git mit-config lint status duplicated-trailers
╭─────────────────────┬─────────╮
│ Lint ┆ Status │
╞═════════════════════╪═════════╡
│ duplicated-trailers ┆ enabled │
╰─────────────────────┴─────────╯
Using message
Demonstration Commit Message
This is a commit message that has trailers and is valid
Co-authored-by: Billie Thompson <billie@example.com>
Signed-off-by: Someone Else <someone@example.com>
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
Demonstration Commit Message
This is a commit message that has trailers and is invalid
Co-authored-by: Billie Thompson <billie@example.com>
Co-authored-by: Billie Thompson <billie@example.com>
Signed-off-by: Someone Else <someone@example.com>
Signed-off-by: Someone Else <someone@example.com>
Relates-to: #315
Relates-to: #315
Committing will fail.
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: DuplicatedTrailers (https://git-scm.com/docs/githooks#_commit_msg)
× Your commit message has duplicated trailers
╭─[6:1]
5 │ Co-authored-by: Billie Thompson <billie@example.com>
6 │ Co-authored-by: Billie Thompson <billie@example.com>
· ──────────────────────────┬─────────────────────────
· ╰── Duplicated `Co-authored-by`
7 │ Signed-off-by: Someone Else <someone@example.com>
8 │ Signed-off-by: Someone Else <someone@example.com>
· ────────────────────────┬────────────────────────
· ╰── Duplicated `Signed-off-by`
9 │ Relates-to: #315
10 │ Relates-to: #315
· ────────┬───────
· ╰── Duplicated `Relates-to`
╰────
help: These are normally added accidentally when you're rebasing or amending
to a commit, sometimes in the text editor, but often by git hooks.
You can fix this by deleting the duplicated "Co-authored-by",
"Relates-to", "Signed-off-by" fields
The style from the git book, that directly affects the operation of git:
If there is a body, enforce a gap between it and the subject.
On an empty repository
git mit-config lint status subject-not-separated-from-body
╭─────────────────────────────────┬─────────╮
│ Lint ┆ Status │
╞═════════════════════════════════╪═════════╡
│ subject-not-separated-from-body ┆ enabled │
╰─────────────────────────────────┴─────────╯
Using message
Demonstration Commit Message
This is a commit message that is valid
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
Demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: SubjectNotSeparateFromBody (https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
× Your commit message is missing a blank line between the subject and the
│ body
╭─[2:1]
1 │ Demonstration Commit Message
2 │ This is a commit message that is invalid
· ────────────────────┬───────────────────
· ╰── Missing blank line
╰────
help: Most tools that render and parse commit messages, expect commit
messages to be in the form of subject and body. This includes git
itself in tools like git-format-patch. If you don't include this you
may see strange behaviour from git and any related tools.
To fix this separate subject from body with a blank line
After 72 characters, git will truncate commit messages in the history view, this prevents that
On an empty repository
git mit-config lint status subject-longer-than-72-characters
╭───────────────────────────────────┬─────────╮
│ Lint ┆ Status │
╞═══════════════════════════════════╪═════════╡
│ subject-longer-than-72-characters ┆ enabled │
╰───────────────────────────────────┴─────────╯
Using message
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Demonstration Commit Message
This is a commit message that is valid
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: SubjectLongerThan72Characters (https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
× Your subject is longer than 72 characters
╭─[1:73]
1 │ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
· ┬
· ╰── Too long
2 │
╰────
help: It's important to keep the subject of the commit less than 72
characters because when you look at the git log, that's where it
truncates the message. This means that people won't get the entirety
of the information in your commit.
Please keep the subject line 72 characters or under
After 72 characters, git will truncate commit messages in the history view, this prevents that
On an empty repository
git mit-config lint status body-wider-than-72-characters
╭───────────────────────────────┬─────────╮
│ Lint ┆ Status │
╞═══════════════════════════════╪═════════╡
│ body-wider-than-72-characters ┆ enabled │
╰───────────────────────────────┴─────────╯
Using message
Demonstration Commit Message
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
This is a commit message that is valid
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
Demonstration Commit Message
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: BodyWiderThan72Characters (https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
× Your commit has a body wider than 72 characters
╭─[3:73]
2 │
3 │ ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
· ┬
· ╰── Too long
4 │ This is a commit message that is invalid
╰────
help: It's important to keep the body of the commit narrower than 72
characters because when you look at the git log, that's where it
truncates the message. This means that people won't get the entirety
of the information in your commit.
You can fix this by making the lines in your body no more than 72
characters
The style from the git book, but that doesn't affect using git
Detect a subject line that is not capitalised
On an empty repository
git mit-config lint status subject-line-not-capitalized
╭──────────────────────────────┬──────────╮
│ Lint ┆ Status │
╞══════════════════════════════╪══════════╡
│ subject-line-not-capitalized ┆ disabled │
╰──────────────────────────────┴──────────╯
Enable it with
git mit-config lint enable subject-line-not-capitalized
Using message
Demonstration Commit Message
This is a commit message that is valid
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: SubjectNotCapitalized (https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
× Your commit message is missing a capital letter
╭─[1:1]
1 │ demonstration Commit Message
· ┬
· ╰── Not capitalised
2 │
╰────
help: The subject line is a title, and as such should be capitalised.
You can fix this by capitalising the first character in the subject
Disable it with
git mit-config lint disable subject-line-not-capitalized
Detect a subject line that is not capitalised
On an empty repository
git mit-config lint status subject-line-ends-with-period
╭───────────────────────────────┬──────────╮
│ Lint ┆ Status │
╞═══════════════════════════════╪══════════╡
│ subject-line-ends-with-period ┆ disabled │
╰───────────────────────────────┴──────────╯
Enable it with
git mit-config lint enable subject-line-ends-with-period
Using message
Demonstration Commit Message
This is a commit message that is valid
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
Demonstration Commit Message.
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: SubjectEndsWithPeriod (https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines)
× Your commit message ends with a period
╭─[1:29]
1 │ Demonstration Commit Message.
· ┬
· ╰── Unneeded period
2 │
╰────
help: It's important to keep your commits short, because we only have a
limited number of characters to use (72) before the subject line is
truncated. Full stops aren't normally in subject lines, and take up an
extra character, so we shouldn't use them in commit message subjects.
You can fix this by removing the period
Disable it with
git mit-config lint disable subject-line-ends-with-period
The conventional changelog is a scheme of commit messages used to allow for automation of changelog generation and releases. It's particularly useful for monorepos.
On an empty repository
git mit-config lint status not-conventional-commit
╭─────────────────────────┬──────────╮
│ Lint ┆ Status │
╞═════════════════════════╪══════════╡
│ not-conventional-commit ┆ disabled │
╰─────────────────────────┴──────────╯
Enable it with
git mit-config lint enable not-conventional-commit
Using message
fix: correct minor typos in code
see the issue for details
on typos fixed.
Reviewed-by: Z
Refs #133
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
Demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: NotConventionalCommit (https://www.conventionalcommits.org/)
× Your commit message isn't in conventional style
╭─[1:1]
1 │ Demonstration Commit Message
· ──────────────┬─────────────
· ╰── Not conventional
2 │
╰────
help: It's important to follow the conventional commit style when creating
your commit message. By using this style we can automatically
calculate the version of software using deployment pipelines, and also
generate changelogs and other useful information without human
interaction.
You can fix it by following style
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Disable it with
git mit-config lint disable not-conventional-commit
Check for the presence of issue Ids
Check for the presence of a Pivotal Tracker ID
On an empty repository
git mit-config lint status pivotal-tracker-id-missing
╭────────────────────────────┬──────────╮
│ Lint ┆ Status │
╞════════════════════════════╪══════════╡
│ pivotal-tracker-id-missing ┆ disabled │
╰────────────────────────────┴──────────╯
Enable it with
git mit-config lint enable pivotal-tracker-id-missing
Using message
Demonstration Commit Message
This is a commit message that is valid
[#12345884]
# some comment
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: PivotalTrackerIdMissing (https://www.pivotaltracker.com/help/api?version=v5#Tracker_Updates_in_SCM_Post_Commit_Hooks)
× Your commit message is missing a Pivotal Tracker ID
╭─[3:1]
2 │
3 │ This is a commit message that is invalid
· ────────────────────┬───────────────────
· ╰── No Pivotal Tracker ID
╰────
help: It's important to add the ID because it allows code to be linked back
to the stories it was done for, it can provide a chain of custody for
code for audit purposes, and it can give future explorers of the
codebase insight into the wider organisational need behind the change.
We may also use it for automation purposes, like generating changelogs
or notification emails.
You can fix this by adding the Id in one of the styles below to the
commit message
[Delivers #12345678]
[fixes #12345678]
[finishes #12345678]
[#12345884 #12345678]
[#12345884,#12345678]
[#12345678],[#12345884]
This will address [#12345884]
Disable it with
git mit-config lint disable pivotal-tracker-id-missing
Check for the presence of a JIRA Issue Key
On an empty repository
git mit-config lint status jira-issue-key-missing
╭────────────────────────┬──────────╮
│ Lint ┆ Status │
╞════════════════════════╪══════════╡
│ jira-issue-key-missing ┆ disabled │
╰────────────────────────┴──────────╯
Enable it with
git mit-config lint enable jira-issue-key-missing
Using message
Demonstration Commit Message
This is a commit message that is valid
JRA-123
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: JiraIssueKeyMissing (https://support.atlassian.com/jira-software-cloud/docs/what-is-an-issue/#Workingwithissues-Projectkeys)
× Your commit message is missing a JIRA Issue Key
╭─[3:1]
2 │
3 │ This is a commit message that is invalid
· ────────────────────┬───────────────────
· ╰── No JIRA Issue Key
╰────
help: It's important to add the issue key because it allows us to link code
back to the motivations for doing it, and in some cases provide an
audit trail for compliance purposes.
You can fix this by adding a key like `JRA-123` to the commit message
Disable it with
git mit-config lint disable jira-issue-key-missing
Check for the presence of a GitHub ID
On an empty repository
git mit-config lint status github-id-missing
╭───────────────────┬──────────╮
│ Lint ┆ Status │
╞═══════════════════╪══════════╡
│ github-id-missing ┆ disabled │
╰───────────────────┴──────────╯
Enable it with
git mit-config lint enable github-id-missing
Using message
Demonstration Commit Message
This is a commit message that is valid
GH-123
Committing will succeed
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Using message
demonstration Commit Message
This is a commit message that is invalid
Committing will fail
echo $RANDOM > changes
git add changes
git commit --message="$(cat message)"
Error: GitHubIdMissing (https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls#issues-and-pull-requests)
× Your commit message is missing a GitHub ID
╭─[3:1]
2 │
3 │ This is a commit message that is invalid
· ────────────────────┬───────────────────
· ╰── No GitHub ID
╰────
help: It's important to add the issue ID because it allows us to link code
back to the motivations for doing it, and because we can help people
exploring the repository link their issues to specific bits of code.
You can fix this by adding a ID like the following examples:
#642
GH-642
AnUser/git-mit#642
AnOrganisation/git-mit#642
fixes #642
Be careful just putting '#642' on a line by itself, as '#' is the
default comment character
Disable it with
git mit-config lint disable github-id-missing