Debian Codegraph @

docs/configuration.md

raw symbols SCIP
1 # Configuration
2 Gitlint can be configured through different means.
3
4 ## The .gitlint file
5 You can modify gitlint's behavior by adding a `.gitlint` file to your git repository.
6
7 Generate a default `.gitlint` config file by running:
8 ```sh
9 gitlint generate-config
10 ```
11 You can also use a different config file like so:
12
13 ```sh
14 gitlint --config myconfigfile.ini
15 ```
16
17 The block below shows a sample `.gitlint` file. Details about rule config options can be found on the
18 [Rules](rules.md) page, details about the `[general]` section can be found in the
19 [General Configuration](configuration.md#general-configuration) section of this page.
20
21 ```ini
22 # Edit this file as you like.
23 #
24 # All these sections are optional. Each section with the exception of [general] represents
25 # one rule and each key in it is an option for that specific rule.
26 #
27 # Rules and sections can be referenced by their full name or by id. For example
28 # section "[body-max-line-length]" could also be written as "[B1]". Full section names are
29 # used in here for clarity.
30 # Rule reference documentation: http://jorisroovers.github.io/gitlint/rules/
31 #
32 # Use 'gitlint generate-config' to generate a config file with all possible options
33 [general]
34 # Ignore certain rules (comma-separated list), you can reference them by their
35 # id or by their full name
36 ignore=title-trailing-punctuation, T3
37
38 # verbosity should be a value between 1 and 3, the commandline -v flags take
39 # precedence over this
40 verbosity = 2
41
42 # By default gitlint will ignore merge, revert, fixup, fixup=amend, and squash commits.
43 ignore-merge-commits=true
44 ignore-revert-commits=true
45 ignore-fixup-commits=true
46 ignore-fixup-amend-commits=true
47 ignore-squash-commits=true
48
49 # Ignore any data sent to gitlint via stdin
50 ignore-stdin=true
51
52 # Fetch additional meta-data from the local repository when manually passing a
53 # commit message to gitlint via stdin or --commit-msg. Disabled by default.
54 staged=true
55
56 # Hard fail when the target commit range is empty. Note that gitlint will
57 # already fail by default on invalid commit ranges. This option is specifically
58 # to tell gitlint to fail on *valid but empty* commit ranges.
59 # Disabled by default.
60 fail-without-commits=true
61
62 # Whether to use Python `search` instead of `match` semantics in rules that use
63 # regexes. Context: https://github.com/jorisroovers/gitlint/issues/254
64 # Disabled by default, but will be enabled by default in the future.
65 regex-style-search=true
66
67 # Enable debug mode (prints more output). Disabled by default.
68 debug=true
69
70 # Enable community contributed rules
71 # See http://jorisroovers.github.io/gitlint/contrib_rules for details
72 contrib=contrib-title-conventional-commits,CC1
73
74 # Set the extra-path where gitlint will search for user defined rules
75 # See http://jorisroovers.github.io/gitlint/user_defined_rules for details
76 extra-path=examples/
77
78 # This is an example of how to configure the "title-max-length" rule and
79 # set the line-length it enforces to 80
80 [title-max-length]
81 line-length=80
82
83 # Conversely, you can also enforce minimal length of a title with the
84 # "title-min-length" rule:
85 [title-min-length]
86 min-length=5
87
88 [title-must-not-contain-word]
89 # Comma-separated list of words that should not occur in the title. Matching is case
90 # insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
91 # will not cause a violation, but "WIP: my title" will.
92 words=wip
93
94 [title-match-regex]
95 # python like regex (https://docs.python.org/3/library/re.html) that the
96 # commit-msg title must be matched to.
97 # Note that the regex can contradict with other rules if not used correctly
98 # (e.g. title-must-not-contain-word).
99 regex=^US[0-9]*
100
101 [body-max-line-length]
102 line-length=120
103
104 [body-min-length]
105 min-length=5
106
107 [body-is-missing]
108 # Whether to ignore this rule on merge commits (which typically only have a title)
109 # default = True
110 ignore-merge-commits=false
111
112 [body-changed-file-mention]
113 # List of files that need to be explicitly mentioned in the body when they are changed
114 # This is useful for when developers often erroneously edit certain files or git submodules.
115 # By specifying this rule, developers can only change the file when they explicitly
116 # reference it in the commit message.
117 files=gitlint-core/gitlint/rules.py,README.md
118
119 [body-match-regex]
120 # python-style regex that the commit-msg body must match.
121 # E.g. body must end in My-Commit-Tag: foo
122 regex=My-Commit-Tag: foo$
123
124 [author-valid-email]
125 # python like regex (https://docs.python.org/3/library/re.html) that the
126 # commit author email address should be matched to
127 # E.g.: For example, use the following regex if you only want to allow email
128 # addresses from foo.com
129 regex=[^@][email protected]
130
131 [ignore-by-title]
132 # Ignore certain rules for commits of which the title matches a regex
133 # E.g. Match commit titles that start with "Release"
134 regex=^Release(.*)
135
136 # Ignore certain rules, you can reference them by their id or by their full name
137 # Use 'all' to ignore all rules
138 ignore=T1,body-min-length
139
140 [ignore-by-body]
141 # Ignore certain rules for commits of which the body has a line that matches a regex
142 # E.g. Match bodies that have a line that that contain "release"
143 regex=(.*)release(.*)
144 #
145 # Ignore certain rules, you can reference them by their id or by their full name
146 # Use 'all' to ignore all rules
147 ignore=T1,body-min-length
148
149 [ignore-body-lines]
150 # Ignore certain lines in a commit body that match a regex.
151 # E.g. Ignore all lines that start with 'Co-Authored-By'
152 regex=^Co-Authored-By
153
154 [ignore-by-author-name]
155 # Ignore certain rules for commits of which the author name matches a regex
156 # E.g. Match commits made by dependabot
157 regex=(.*)dependabot(.*)
158
159 # Ignore certain rules, you can reference them by their id or by their full name
160 # Use 'all' to ignore all rules
161 ignore=T1,body-min-length
162
163 # This is a contrib rule - a community contributed rule. These are disabled by default.
164 # You need to explicitly enable them one-by-one by adding them to the "contrib" option
165 # under [general] section above.
166 [contrib-title-conventional-commits]
167 # Specify allowed commit types. For details see: https://www.conventionalcommits.org/
168 types = bugfix,user-story,epic
169 ```
170
171 ## Commandline config
172
173 You can also use one or more `-c` flags like so:
174
175 ```
176 $ gitlint -c general.verbosity=2 -c title-max-length.line-length=80 -c B1.line-length=100
177 ```
178 The generic config flag format is `-c <rule>.<option>=<value>` and supports all the same rules and options which
179 you can also use in a `.gitlint` config file.
180
181 ## Commit specific config
182
183 You can also configure gitlint by adding specific lines to your commit message.
184 For now, we only support ignoring commits by adding `gitlint-ignore: all` to the commit
185 message like so:
186
187 ```
188 WIP: This is my commit message
189
190 I want gitlint to ignore this entire commit message.
191 gitlint-ignore: all
192 ```
193
194 `gitlint-ignore: all` can occur on any line, as long as it is at the start of the line.
195
196 You can also specify specific rules to be ignored as follows:
197 ```
198 WIP: This is my commit message
199
200 I want gitlint to ignore this entire commit message.
201 gitlint-ignore: T1, body-hard-tab
202 ```
203
204
205
206 ## Configuration precedence
207 gitlint configuration is applied in the following order of precedence:
208
209 1. Commit specific config (e.g.: `gitlint-ignore: all` in the commit message)
210 2. Configuration Rules (e.g.: [ignore-by-title](rules.md#i1-ignore-by-title))
211 3. Commandline convenience flags (e.g.: `-vv`, `--silent`, `--ignore`)
212 4. Environment variables (e.g.: `GITLINT_VERBOSITY=3`)
213 5. Commandline configuration flags (e.g.: `-c title-max-length=123`)
214 6. Configuration file (local `.gitlint` file, or file specified using `-C`/`--config`)
215 7. Default gitlint config
216
217 ## General Options
218 Below we outline all configuration options that modify gitlint's overall behavior. These options can be specified
219 using commandline flags or in `[general]` section in a `.gitlint` configuration file.
220
221 ### silent
222
223 Enable silent mode (no output). Use [exit](index.md#exit-codes) code to determine result.
224
225 | Default value | gitlint version | commandline flag | environment variable |
226 | ------------- | --------------- | ---------------- | -------------------- |
227 | `False` | >= 0.1.0 | `--silent` | `GITLINT_SILENT` |
228
229 #### Examples
230 ```sh
231 # CLI
232 gitlint --silent
233 GITLINT_SILENT=1 gitlint # using env variable
234 ```
235 ------------------------------------------------------------------------------------------------------------------------
236
237 ### verbosity
238
239 Amount of output gitlint will show when printing errors.
240
241 | Default value | gitlint version | commandline flag | environment variable |
242 | ------------- | --------------- | ---------------- | -------------------- |
243 | 3 | >= 0.1.0 | `-v` | `GITLINT_VERBOSITY` |
244
245
246 #### Examples
247 ```sh
248 # CLI
249 gitlint -vvv # default (level 3)
250 gitlint -vv # less output (level 2)
251 gitlint -v # even less (level 1)
252 gitlint --silent # no output (level 0)
253 gitlint -c general.verbosity=1 # Set specific level
254 gitlint -c general.verbosity=0 # Same as --silent
255 GITLINT_VERBOSITY=2 gitlint # using env variable
256 ```
257 ```ini
258 # .gitlint
259 [general]
260 verbosity=2
261 ```
262 ------------------------------------------------------------------------------------------------------------------------
263
264 ### ignore
265
266 Comma separated list of rules to ignore (by name or id).
267
268 | Default value | gitlint version | commandline flag | environment variable |
269 | ---------------- | --------------- | ---------------- | -------------------- |
270 | [] (=empty list) | >= 0.1.0 | `--ignore` | `GITLINT_IGNORE` |
271
272 #### Examples
273 ```sh
274 # CLI
275 gitlint --ignore=body-min-length # ignore single rule
276 gitlint --ignore=T1,body-min-length # ignore multiple rule
277 gitlint -c general.ignore=T1,body-min-length # different way of doing the same
278 GITLINT_IGNORE=T1,body-min-length gitlint # using env variable
279 ```
280 ```ini
281 #.gitlint
282 [general]
283 ignore=T1,body-min-length
284 ```
285 ------------------------------------------------------------------------------------------------------------------------
286
287 ### debug
288
289 Enable debugging output.
290
291 | Default value | gitlint version | commandline flag | environment variable |
292 | ------------- | --------------- | ---------------- | -------------------- |
293 | false | >= 0.7.1 | `--debug` | `GITLINT_DEBUG` |
294
295 #### Examples
296 ```sh
297 # CLI
298 gitlint --debug
299 GITLINT_DEBUG=1 gitlint # using env variable
300 # --debug is special, the following does NOT work
301 # gitlint -c general.debug=true
302 ```
303 ------------------------------------------------------------------------------------------------------------------------
304
305 ### target
306
307 Target git repository gitlint should be linting against.
308
309 | Default value | gitlint version | commandline flag | environment variable |
310 | ------------- | --------------- | ---------------- | -------------------- |
311 | (empty) | >= 0.8.0 | `--target` | `GITLINT_TARGET` |
312
313 #### Examples
314 ```sh
315 # CLI
316 gitlint --target=/home/joe/myrepo/
317 gitlint -c general.target=/home/joe/myrepo/ # different way of doing the same
318 GITLINT_TARGET=/home/joe/myrepo/ gitlint # using env variable
319 ```
320 ```ini
321 #.gitlint
322 [general]
323 target=/home/joe/myrepo/
324 ```
325 ------------------------------------------------------------------------------------------------------------------------
326
327 ### config
328
329 Path where gitlint looks for a config file.
330
331 | Default value | gitlint version | commandline flag | environment variable |
332 | ------------- | --------------- | ---------------- | -------------------- |
333 | `.gitlint` | >= 0.1.0 | `--config` | `GITLINT_CONFIG` |
334
335 #### Examples
336 ```sh
337 gitlint --config=/home/joe/gitlint.ini
338 gitlint -C /home/joe/gitlint.ini # different way of doing the same
339 GITLINT_CONFIG=/home/joe/gitlint.ini # using env variable
340 ```
341 ------------------------------------------------------------------------------------------------------------------------
342
343 ### extra-path
344
345 Path where gitlint looks for [user-defined rules](user_defined_rules.md).
346
347 | Default value | gitlint version | commandline flag | environment variable |
348 | ------------- | --------------- | ---------------- | -------------------- |
349 | (empty) | >= 0.8.0 | `--extra-path` | `GITLINT_EXTRA_PATH` |
350
351 #### Examples
352 ```sh
353 # CLI
354 gitlint --extra-path=/home/joe/rules/
355 gitlint -c general.extra-path=/home/joe/rules/ # different way of doing the same
356 GITLINT_EXTRA_PATH=/home/joe/rules/ gitlint # using env variable
357 ```
358 ```ini
359 #.gitlint
360 [general]
361 extra-path=/home/joe/rules/
362 ```
363 ------------------------------------------------------------------------------------------------------------------------
364 ### contrib
365
366 Comma-separated list of [Contrib rules](contrib_rules.md) to enable (by name or id).
367
368 | Default value | gitlint version | commandline flag | environment variable |
369 | ------------- | --------------- | ---------------- | -------------------- |
370 | (empty) | >= 0.12.0 | `--contrib` | `GITLINT_CONTRIB` |
371
372 #### Examples
373 ```sh
374 # CLI
375 gitlint --contrib=contrib-title-conventional-commits,CC1
376 # different way of doing the same
377 gitlint -c general.contrib=contrib-title-conventional-commits,CC1
378 # using env variable
379 GITLINT_CONTRIB=contrib-title-conventional-commits,CC1 gitlint
380 ```
381 ```ini
382 #.gitlint
383 [general]
384 contrib=contrib-title-conventional-commits,CC1
385 ```
386 ------------------------------------------------------------------------------------------------------------------------
387
388 ### staged
389
390 Attempt smart guesses about meta info (like author name, email, branch, changed files, etc) when manually passing a
391 commit message to gitlint via stdin or `--commit-msg`.
392
393 Since in such cases no actual git commit exists (yet) for the message being linted, gitlint
394 needs to apply some heuristics (like checking `git config` and any staged changes) to make a smart guess about what the
395 likely author name, email, commit date, changed files and branch of the ensuing commit would be.
396
397 When not using the `--staged` flag while linting a commit message via stdin or `--commit-msg`, gitlint will only have
398 access to the commit message itself for linting and won't be able to enforce rules like
399 [M1:author-valid-email](rules.md#m1-author-valid-email).
400
401 | Default value | gitlint version | commandline flag | environment variable |
402 | ------------- | --------------- | ---------------- | -------------------- |
403 | false | >= 0.13.0 | `--staged` | `GITLINT_STAGED` |
404
405 #### Examples
406 ```sh
407 # CLI
408 gitlint --staged
409 gitlint -c general.staged=true # different way of doing the same
410 GITLINT_STAGED=1 gitlint # using env variable
411 ```
412 ```ini
413 #.gitlint
414 [general]
415 staged=true
416 ```
417 ------------------------------------------------------------------------------------------------------------------------
418
419 ### fail-without-commits
420
421 Hard fail when the target commit range is empty. Note that gitlint will
422 already fail by default on invalid commit ranges. This option is specifically
423 to tell gitlint to fail on **valid but empty** commit ranges.
424
425 | Default value | gitlint version | commandline flag | environment variable |
426 | ------------- | --------------- | ------------------------ | ------------------------------ |
427 | false | >= 0.15.2 | `--fail-without-commits` | `GITLINT_FAIL_WITHOUT_COMMITS` |
428
429 #### Examples
430 ```sh
431 # CLI
432 # The following will cause gitlint to hard fail (i.e. exit code > 0)
433 # since HEAD..HEAD is a valid but empty commit range.
434 gitlint --fail-without-commits --commits HEAD..HEAD
435 GITLINT_FAIL_WITHOUT_COMMITS=1 gitlint # using env variable
436 ```
437 ```ini
438 #.gitlint
439 [general]
440 fail-without-commits=true
441 ```
442
443 ---
444 ### regex-style-search
445
446 Whether to use Python `re.search()` instead of `re.match()` semantics in all built-in rules that use regular expressions.
447
448 | Default value | gitlint version | commandline flag | environment variable |
449 | ------------- | --------------- | ---------------- | -------------------- |
450 | false | >= 0.18.0 | Not Available | Not Available |
451
452 !!! important
453 At this time, `regex-style-search` is **disabled** by default, but it will be **enabled** by default in the future.
454
455
456
457 Gitlint will log a warning when you're using a rule that uses a custom regex and this option is not enabled:
458
459 ```plain
460 WARNING: I1 - ignore-by-title: gitlint will be switching from using Python regex 'match' (match beginning) to
461 'search' (match anywhere) semantics. Please review your ignore-by-title.regex option accordingly.
462 To remove this warning, set general.regex-style-search=True.
463 More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
464 ```
465
466 *If you don't have any custom regex specified, gitlint will not log a warning and no action is needed.*
467
468 **To remove the warning:**
469
470 1. Review your regex in the rules gitlint warned for and ensure it's still accurate when using [`re.search()` semantics](https://docs.python.org/3/library/re.html#search-vs-match).
471 2. Enable `regex-style-search` in your `.gitlint` file (or using [any other way to configure gitlint](http://127.0.0.1:8000/gitlint/configuration/)):
472
473 ```ini
474 [general]
475 regex-style-search=true
476 ```
477
478 #### More context
479 Python offers [two different primitive operations based on regular expressions](https://docs.python.org/3/library/re.html#search-vs-match):
480 `re.match()` checks for a match only at the beginning of the string, while `re.search()` checks for a match anywhere
481 in the string.
482
483
484
485 Most rules in gitlint already use `re.search()` instead of `re.match()`, but there's a few notable exceptions that
486 use `re.match()`, which can lead to unexpected matching behavior.
487
488 - M1 - author-valid-email
489 - I1 - ignore-by-title
490 - I2 - ignore-by-body
491 - I3 - ignore-body-lines
492 - I4 - ignore-by-author-name
493
494 The `regex-style-search` option is meant to fix this inconsistency. Setting it to `true` will force the above rules to
495 use `re.search()` instead of `re.match()`. For detailed context, see [issue #254](https://github.com/jorisroovers/gitlint/issues/254).
496
497
498 #### Examples
499 ```sh
500 # CLI
501 gitlint -c general.regex-style-search=true
502 ```
503 ```ini
504 #.gitlint
505 [general]
506 regex-style-search=true
507 ```
508 ------------------------------------------------------------------------------------------------------------------------
509 ### ignore-stdin
510
511 Ignore any stdin data. Sometimes useful when running gitlint in a CI server.
512
513 | Default value | gitlint version | commandline flag | environment variable |
514 | ------------- | --------------- | ---------------- | ---------------------- |
515 | false | >= 0.12.0 | `--ignore-stdin` | `GITLINT_IGNORE_STDIN` |
516
517 #### Examples
518 ```sh
519 # CLI
520 gitlint --ignore-stdin
521 gitlint -c general.ignore-stdin=true # different way of doing the same
522 GITLINT_IGNORE_STDIN=1 gitlint # using env variable
523 ```
524 ```ini
525 #.gitlint
526 [general]
527 ignore-stdin=true
528 ```
529 ------------------------------------------------------------------------------------------------------------------------
530
531 ### ignore-merge-commits
532
533 Whether or not to ignore merge commits.
534
535 | Default value | gitlint version | commandline flag | environment variable |
536 | ------------- | --------------- | ---------------- | -------------------- |
537 | true | >= 0.7.0 | Not Available | Not Available |
538
539 #### Examples
540 ```sh
541 # CLI
542 gitlint -c general.ignore-merge-commits=false
543 ```
544 ```ini
545 #.gitlint
546 [general]
547 ignore-merge-commits=false
548 ```
549 ------------------------------------------------------------------------------------------------------------------------
550
551 ### ignore-revert-commits
552
553 Whether or not to ignore revert commits.
554
555 | Default value | gitlint version | commandline flag | environment variable |
556 | ------------- | --------------- | ---------------- | -------------------- |
557 | true | >= 0.13.0 | Not Available | Not Available |
558
559 #### Examples
560 ```sh
561 # CLI
562 gitlint -c general.ignore-revert-commits=false
563 ```
564 ```ini
565 #.gitlint
566 [general]
567 ignore-revert-commits=false
568 ```
569 ------------------------------------------------------------------------------------------------------------------------
570
571 ### ignore-fixup-commits
572
573 Whether or not to ignore [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits.
574
575 | Default value | gitlint version | commandline flag | environment variable |
576 | ------------- | --------------- | ---------------- | -------------------- |
577 | true | >= 0.9.0 | Not Available | Not Available |
578
579 #### Examples
580 ```sh
581 # CLI
582 gitlint -c general.ignore-fixup-commits=false
583 ```
584 ```ini
585 #.gitlint
586 [general]
587 ignore-fixup-commits=false
588 ```
589 ------------------------------------------------------------------------------------------------------------------------
590
591 ### ignore-fixup-amend-commits
592
593 Whether or not to ignore [fixup=amend](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt) commits.
594
595 | Default value | gitlint version | commandline flag | environment variable |
596 | ------------- | --------------- | ---------------- | -------------------- |
597 | true | >= 0.18.0 | Not Available | Not Available |
598
599 #### Examples
600 ```sh
601 # CLI
602 gitlint -c general.ignore-fixup-amend-commits=false
603 ```
604 ```ini
605 #.gitlint
606 [general]
607 ignore-fixup-amend-commits=false
608 ```
609 ------------------------------------------------------------------------------------------------------------------------
610
611 ### ignore-squash-commits
612
613 Whether or not to ignore [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) commits.
614
615 | Default value | gitlint version | commandline flag | environment variable |
616 | ------------- | --------------- | ---------------- | -------------------- |
617 | true | >= 0.9.0 | Not Available | Not Available |
618
619 #### Examples
620 ```sh
621 # CLI
622 gitlint -c general.ignore-squash-commits=false
623 ```
624 ```ini
625 #.gitlint
626 [general]
627 ignore-squash-commits=false
628 ```