1
0
Fork 0

Adding upstream version 0.13.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 05:54:40 +01:00
parent 1805ece79d
commit d8f166e6bb
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
167 changed files with 15302 additions and 0 deletions

View file

@ -0,0 +1,5 @@
WIP: This is the title of a commit message.
The second line should typically be empty
Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120.
# All of the following is ignored
# This line starts with a hard tab

View file

@ -0,0 +1,6 @@
This h@s $pecialCh@rs!
Commit body
with more
than 3 lines
and no signed off by line

View file

@ -0,0 +1,5 @@
This is the title of a commit message that is over 72 characters and contains hard tabs and trailing whitespace and the word wiping
This line should not contain text
Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120.
# This line will be ignored by gitlint because it starts with a #.

View file

@ -0,0 +1,3 @@
This is the wip title of a commit message!
Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120.

View file

@ -0,0 +1,3 @@
This title has a leading tab whitespace
tooshort

View file

@ -0,0 +1 @@
US1234: This commit message has no body

View file

@ -0,0 +1 @@
Merge "US1234: This merge has no body and that's OK"

View file

@ -0,0 +1,4 @@
This is the title of a commit message that is over 72 characters and contains hard tabs and trailing whitespace and the word wiping
This line should not contain text
Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120.
gitlint-ignore: all

View file

@ -0,0 +1,6 @@
This is the title of a commit message that is over 72 characters and contains hard tabs and trailing whitespace and the word wiping
This line should not contain text
Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120.
# This line will be ignored by gitlint because it starts with a #.
gitlint-ignore: B4, title-hard-tab

View file

@ -0,0 +1,7 @@
Merge: "This is a merge commit with a long title that most definitely exceeds the normal limit of 72 chars"
This line should be empty
This is the first line is meant to test a line that exceeds the maximum line length of 80 characters.
You will notice that gitlint ignores all of these errors by default because this is a merge commit.
If you want to change this behavior, set the following option: 'general.ignore-merge-commits=false'

58
examples/gitlint Normal file
View file

@ -0,0 +1,58 @@
# Edit this file as you like.
#
# All these sections are optional. Each section with the exception of general represents
# one rule and each key in it is an option for that specific rule.
#
# Rules and sections can be referenced by their full name or by id. For example
# section "[body-max-line-length]" could be written as "[B1]". Full section names are
# used in here for clarity.
# Rule reference documentation: http://jorisroovers.github.io/gitlint/rules/
#
# Note that this file is not exhaustive, it's just an example
# Use 'gitlint generate-config' to generate a config file with all possible options
[general]
ignore=title-trailing-punctuation, T3
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
verbosity = 2
# By default gitlint will ignore merge commits. Set to 'false' to disable.
ignore-merge-commits=true
# Enable debug mode (prints more output). Disabled by default
debug = true
# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
# extra-path=examples/
[title-max-length]
line-length=50
[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
# will not cause a violation, but "WIP: my title" will.
words=wip,title
[title-match-regex]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit-msg title must be matched to.
# Note that the regex can contradict with other rules if not used correctly
# (e.g. title-must-not-contain-word).
regex=^US[0-9]*
[body-max-line-length]
line-length=72
[body-min-length]
min-length=5
[body-is-missing]
# Whether to ignore this rule on merge commits (which typically only have a title)
# default = True
ignore-merge-commits=false
[body-changed-file-mention]
# List of files that need to be explicitly mentioned in the body when they are changed
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
files=gitlint/rules.py,README.md

View file

@ -0,0 +1,87 @@
from gitlint.rules import CommitRule, RuleViolation
from gitlint.options import IntOption, ListOption
from gitlint import utils
"""
The classes below are examples of user-defined CommitRules. Commit rules are gitlint rules that
act on the entire commit at once. Once the rules are discovered, gitlint will automatically take care of applying them
to the entire commit. This happens exactly once per commit.
A CommitRule contrasts with a LineRule (see examples/my_line_rules.py) in that a commit rule is only applied once on
an entire commit. This allows commit rules to implement more complex checks that span multiple lines and/or checks
that should only be done once per gitlint run.
While every LineRule can be implemented as a CommitRule, it's usually easier and more concise to go with a LineRule if
that fits your needs.
"""
class BodyMaxLineCount(CommitRule):
# A rule MUST have a human friendly name
name = "body-max-line-count"
# A rule MUST have a *unique* id, we recommend starting with UC (for User-defined Commit-rule).
id = "UC1"
# A rule MAY have an option_spec if its behavior should be configurable.
options_spec = [IntOption('max-line-count', 3, "Maximum body line count")]
def validate(self, commit):
line_count = len(commit.message.body)
max_line_count = self.options['max-line-count'].value
if line_count > max_line_count:
message = "Body contains too many lines ({0} > {1})".format(line_count, max_line_count)
return [RuleViolation(self.id, message, line_nr=1)]
class SignedOffBy(CommitRule):
""" This rule will enforce that each commit contains a "Signed-Off-By" line.
We keep things simple here and just check whether the commit body contains a line that starts with "Signed-Off-By".
"""
# A rule MUST have a human friendly name
name = "body-requires-signed-off-by"
# A rule MUST have a *unique* id, we recommend starting with UC (for User-defined Commit-rule).
id = "UC2"
def validate(self, commit):
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
return
return [RuleViolation(self.id, "Body does not contain a 'Signed-Off-By' line", line_nr=1)]
class BranchNamingConventions(CommitRule):
""" This rule will enforce that a commit is part of a branch that meets certain naming conventions.
See GitFlow for real-world example of this: https://nvie.com/posts/a-successful-git-branching-model/
"""
# A rule MUST have a human friendly name
name = "branch-naming-conventions"
# A rule MUST have a *unique* id, we recommend starting with UC (for User-defined Commit-rule).
id = "UC3"
# A rule MAY have an option_spec if its behavior should be configurable.
options_spec = [ListOption('branch-prefixes', ["feature/", "hotfix/", "release/"], "Allowed branch prefixes")]
def validate(self, commit):
violations = []
allowed_branch_prefixes = self.options['branch-prefixes'].value
for branch in commit.branches:
valid_branch_name = False
for allowed_prefix in allowed_branch_prefixes:
if branch.startswith(allowed_prefix):
valid_branch_name = True
break
if not valid_branch_name:
msg = "Branch name '{0}' does not start with one of {1}".format(branch,
utils.sstr(allowed_branch_prefixes))
violations.append(RuleViolation(self.id, msg, line_nr=1))
return violations

45
examples/my_line_rules.py Normal file
View file

@ -0,0 +1,45 @@
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle
from gitlint.options import ListOption
"""
The SpecialChars class below is an example of a user-defined LineRule. Line rules are gitlint rules that only act on a
single line at once. Once the rule is discovered, gitlint will automatically take care of applying this rule
against each line of the commit message title or body (whether it is applied to the title or body is determined by the
`target` attribute of the class).
A LineRule contrasts with a CommitRule (see examples/my_commit_rules.py) in that a commit rule is only applied once on
an entire commit. This allows commit rules to implement more complex checks that span multiple lines and/or checks
that should only be done once per gitlint run.
While every LineRule can be implemented as a CommitRule, it's usually easier and more concise to go with a LineRule if
that fits your needs.
"""
class SpecialChars(LineRule):
""" This rule will enforce that the commit message title does not contain any of the following characters:
$^%@!*() """
# A rule MUST have a human friendly name
name = "title-no-special-chars"
# A rule MUST have a *unique* id, we recommend starting with UL (for User-defined Line-rule), but this can
# really be anything.
id = "UL1"
# A line-rule MUST have a target (not required for CommitRules).
target = CommitMessageTitle
# A rule MAY have an option_spec if its behavior should be configurable.
options_spec = [ListOption('special-chars', ['$', '^', '%', '@', '!', '*', '(', ')'],
"Comma separated list of characters that should not occur in the title")]
def validate(self, line, _commit):
violations = []
# options can be accessed by looking them up by their name in self.options
for char in self.options['special-chars'].value:
if char in line:
violation = RuleViolation(self.id, "Title contains the special character '{0}'".format(char), line)
violations.append(violation)
return violations