summaryrefslogtreecommitdiffstats
path: root/docs/configuration/general_options.md
blob: f18f25a41e6ff1ff22c340e9e42f823f69a66321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
Gitlint has a number of options that modify it's overall behavior, documented below.

## silent
[:octicons-tag-24: v0.1.0][v0.1.0]

Enable silent mode (no output).

| Default value    | Type            | CLI flag         | Env var          |
| ---------------- | --------------- | ---------------- | ---------------- |
| `#!python false` | `#!python bool` | `--silent`, `-s` | `GITLINT_SILENT` |


=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --silent
    ```

=== ":material-application-variable-outline: Env var"
    
    ```sh
    GITLINT_SILENT=1 gitlint 
    ```

## verbosity
[:octicons-tag-24: v0.1.0][v0.1.0]

Amount of output gitlint will show when printing errors.

| Default value | Type           | CLI flag                          | Env var             |
| ------------- | -------------- | --------------------------------- | ------------------- |
| `#!python 3`  | `#!python int` | `--verbose`, `-v`, `-vv`, `-vvv`, | `GITLINT_VERBOSITY` |



=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    verbosity=2
    ```

=== ":octicons-terminal-16: CLI"

    ```sh
    gitlint -vvv                   # default         (level 3)
    gitlint -vv                    # less output     (level 2)
    gitlint -v                     # even less       (level 1)
    gitlint --silent               # no output       (level 0)
    gitlint --verbose 2            # specific level  (level 2)
    gitlint -c general.verbosity=1 # Set specific level
    gitlint -c general.verbosity=0 # Same as --silent
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_VERBOSITY=2 gitlint   
    ```


## ignore
[:octicons-tag-24: v0.1.0][v0.1.0]

Comma separated list of rules to ignore (by name or id).

| Default value              | Type            | CLI flag   | Env var          |
| -------------------------- | --------------- | ---------- | ---------------- |
| `#!python []` (empty list) | `#!python list` | `--ignore` | `GITLINT_IGNORE` |


=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    ignore=T1,body-min-length
    ```

=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --ignore=body-min-length              # ignore single rule
    gitlint --ignore=T1,body-min-length           # ignore multiple rule
    gitlint -c general.ignore=T1,body-min-length  # different way of doing the same
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_IGNORE=T1,body-min-length gitlint
    ```



## debug
[:octicons-tag-24: v0.7.1][v0.7.1]

Enable debugging output.

| Default value    | Type            | CLI flag        | Env var         |
| ---------------- | --------------- | --------------- | --------------- |
| `#!python false` | `#!python bool` | `--debug`, `-d` | `GITLINT_DEBUG` |


=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --debug
    # --debug is special, the following does NOT work
    # gitlint -c general.debug=true
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_DEBUG=1 gitlint
    ```


## target
[:octicons-tag-24: v0.8.0][v0.8.0]

Target git repository gitlint should be linting against.

| Default value                      | Type           | CLI flag   | Env var          |
| ---------------------------------- | -------------- | ---------- | ---------------- |
| `#!python .` (current working dir) | `#!python str` | `--target` | `GITLINT_TARGET` |


=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    target=/home/joe/myrepo/
    ```

=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --target=/home/joe/myrepo/
    gitlint -c general.target=/home/joe/myrepo/  # different way of doing the same
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_TARGET=/home/joe/myrepo/ gitlint
    ```


## commit
[:octicons-tag-24: v0.16.0][v0.16.0]

Git reference of specific commit to lint.

| Default value | Type           | CLI flag   | Env var          |
| ------------- | -------------- | ---------- | ---------------- |
| `(empty)`     | `#!python str` | `--commit` | `GITLINT_COMMIT` |


=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --commit 019cf40580a471a3958d3c346aa8bfd265fe5e16
    gitlint --commit 019cf40  # short SHAs work too
    gitlint --commit HEAD~2   # as do special references
    gitlint --commit mybranch # lint latest commit on a branch 
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_COMMIT=019cf40580a471a3958d3c346aa8bfd265fe5e16 gitlint
    GITLINT_COMMIT=019cf40 gitlint  # short SHAs work too
    GITLINT_COMMIT=HEAD~2 gitlint   # as do special references
    GITLINT_COMMIT=mybranch gitlint # lint latest commit on a branch 
    ```

## commits
[:octicons-tag-24: v0.8.1][v0.8.1]

Range of commits (refspec or comma-separated hashes) to lint.

| Default value     | Type           | CLI flag    | Env var           |
| ----------------- | -------------- | ----------- | ----------------- |
| `#!python "HEAD"` | `#!python str` | `--commits` | `GITLINT_COMMITS` |


=== ":octicons-terminal-16:  CLI"

    ```sh
    # Lint a specific commit range
    gitlint --commits "019cf40...d6bc75a"
    # Lint all commits on a branch
    gitlint --commits mybranch
    # Lint all commits that are different between a branch and your main branch
    gitlint --commits "main..mybranch"
    # Use git's special references
    gitlint --commits "origin/main..HEAD"

    # You can also pass multiple, comma separated commit hashes
    gitlint --commits 019cf40,c50eb150,d6bc75a
    # These can include special references as well
    gitlint --commits HEAD~1,mybranch-name,origin/main,d6bc75a
    # You can also lint a single commit by adding a trailing comma
    gitlint --commits 019cf40,
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    # Lint a specific commit range
    GITLINT_COMMITS="019cf40...d6bc75a" gitlint
    # Lint all commits on a branch
    GITLINT_COMMITS=mybranch gitlint
    # Lint all commits that are different between a branch and your main branch
    GITLINT_COMMITS="main..mybranch" gitlint
    # Use git's special references
    GITLINT_COMMITS="origin/main..HEAD" gitlint

    # You can also pass multiple, comma separated commit hashes
    GITLINT_COMMITS=019cf40,c50eb150,d6bc75a gitlint
    # These can include special references as well
    GITLINT_COMMITS=HEAD~1,mybranch-name,origin/main,d6bc75a gitlint
    # You can also lint a single commit by adding a trailing comma
    GITLINT_COMMITS=019cf40, gitlint
    ```

## config
[:octicons-tag-24: v0.1.0][v0.1.0]

Path where gitlint looks for a config file.

| Default value         | Type           | CLI flag         | Env var          |
| --------------------- | -------------- | ---------------- | ---------------- |
| `#!python ".gitlint"` | `#!python str` | `--config`, `-C` | `GITLINT_CONFIG` |


=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --config=/home/joe/gitlint.ini
    gitlint -C /home/joe/gitlint.ini      # different way of doing the same
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_CONFIG=/home/joe/gitlint.ini 
    ```


## extra-path
[:octicons-tag-24: v0.8.0][v0.8.0]

Path where gitlint looks for [user-defined rules](../rules/user_defined_rules/getting_started.md).

| Default value          | Type           | CLI flag             | Env var              |
| ---------------------- | -------------- | -------------------- | -------------------- |
| `#!python None`(empty) | `#!python str` | `--extra-path`, `-e` | `GITLINT_EXTRA_PATH` |



=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    extra-path=tools/gitlint/myrules # (1)

    # Alternatively, point to a specific file
    [general]
    extra-path=tools/gitlint/myrules/my_rules.py
    ```

    1. This path is relative to the current working directory in which you're executing gitlint.
        ```ini
        # You can also use absolute paths of course
        [general]
        extra-path=/opt/gitlint/my_rules.py
        ```

=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --extra-path "tools/gitlint/myrules" # (1)
    # Alternatively, point to a specific file
    gitlint --extra-path "tools/gitlint/myrules/my_rules.py"
    
    # You can also use -c style config flags
    gitlint -c general.extra-path=tools/gitlint/myrules
    ```

    1. This path is relative to the current working directory in which you're executing gitlint.
        ```sh
        # You can also use absolute paths of course
        gitlint --extra-path "/opt/gitlint/my_rules.py"
        ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_EXTRA_PATH=tools/gitlint/myrules gitlint # (1)
    # Alternatively, point to a specific file
    GITLINT_EXTRA_PATH=tools/gitlint/myrules/my_rules.py gitlint
    ```

    1. This path is relative to the current working directory in which you're executing gitlint.
        ```sh
        # You can also use absolute paths of course
        GITLINT_EXTRA_PATH=/opt/gitlint/myrules gitlint
        ```

## contrib
[:octicons-tag-24: v0.12.0][v0.12.0]

Comma-separated list of [Contrib rules](../rules/contrib_rules.md) to enable (by name or id).

| Default value           | Type           | CLI flag    | Env var           |
| ----------------------- | -------------- | ----------- | ----------------- |
| `#!python None` (empty) | `#!python str` | `--contrib` | `GITLINT_CONTRIB` |


=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    contrib=contrib-title-conventional-commits,CC1
    ```

=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --contrib=contrib-title-conventional-commits,CC1
    # different way of doing the same
    gitlint -c general.contrib=contrib-title-conventional-commits,CC1
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_CONTRIB=contrib-title-conventional-commits,CC1 gitlint
    ```

## msg-filename
[:octicons-tag-24: v0.8.0][v0.8.0]

Path to a file containing the commit-msg to be linted.

| Default value           | Type           | CLI flag         | Env var       |
| ----------------------- | -------------- | ---------------- | ------------- |
| `#!python None` (empty) | `#!python str` | `--msg-filename` | Not Available |



=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --msg-filename=/home/joe/mycommit-msg.txt
    ```

## staged
[:octicons-tag-24: v0.13.0][v0.13.0]

Attempt smart guesses about meta info (like author name, email, branch, changed files, etc) when manually passing a
commit message to gitlint via stdin or `--commit-msg`.

Since in such cases no actual git commit exists (yet) for the message being linted, gitlint
needs to apply some heuristics (like checking `git config` and any staged changes) to make a smart guess about what the
likely author name, email, commit date, changed files and branch of the ensuing commit would be.

When not using the `--staged` flag while linting a commit message via stdin or `--commit-msg`, gitlint will only have
access to the commit message itself for linting and won't be able to enforce rules like
[M1:author-valid-email](../rules/builtin_rules.md#m1-author-valid-email).

| Default value    | Type            | CLI flag   | Env var          |
| ---------------- | --------------- | ---------- | ---------------- |
| `#!python false` | `#!python bool` | `--staged` | `GITLINT_STAGED` |


=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    staged=true
    ```

=== ":octicons-terminal-16:  CLI"

    ```sh
    gitlint --staged
    gitlint -c general.staged=true # different way of doing the same
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_STAGED=1 gitlint      
    ```


## fail-without-commits
[:octicons-tag-24: v0.16.0][v0.16.0]


Hard fail when the target commit range is empty. Note that gitlint will
already fail by default on invalid commit ranges. This option is specifically
to tell gitlint to fail on **valid but empty** commit ranges.

| Default value    | Type            | CLI flag                 | Env var                        |
| ---------------- | --------------- | ------------------------ | ------------------------------ |
| `#!python false` | `#!python bool` | `--fail-without-commits` | `GITLINT_FAIL_WITHOUT_COMMITS` |


=== ":octicons-file-code-16:  .gitlint"
    
    ```ini
    [general]
    fail-without-commits=true
    ```

=== ":octicons-terminal-16:  CLI"

    ```sh
    # The following will cause gitlint to hard fail (i.e. exit code > 0)
    # since HEAD..HEAD is a valid but empty commit range.
    gitlint --fail-without-commits --commits HEAD..HEAD
    ```

=== ":material-application-variable-outline: Env var"

    ```sh
    GITLINT_FAIL_WITHOUT_COMMITS=1 gitlint      
    ```


## regex-style-search
[:octicons-tag-24: v0.18.0][v0.18.0]

Whether to use Python `re.search()` instead of `re.match()` semantics in all built-in rules that use regular expressions. 

??? "More context on **regex-style-search**"

    Python offers [two different primitive operations based on regular expressions](https://docs.python.org/3/library/re.html#search-vs-match): 
    `re.match()` checks for a match only at the beginning of the string, while `re.search()` checks for a match anywhere
    in the string.



    Most rules in gitlint already use `re.search()` instead of `re.match()`, but there's a few notable exceptions that
    use `re.match()`, which can lead to unexpected matching behavior.

    - M1 - author-valid-email
    - I1 - ignore-by-title
    - I2 - ignore-by-body
    - I3 - ignore-body-lines
    - I4 - ignore-by-author-name

    The `regex-style-search` option is meant to fix this inconsistency. Setting it to `true` will force the above rules to
    use `re.search()` instead of `re.match()`. For detailed context, see [issue #254](https://github.com/jorisroovers/gitlint/issues/254).

| Default value    | Type            | CLI flag                                | Env var       |
| ---------------- | --------------- | --------------------------------------- | ------------- |
| `#!python false` | `#!python bool` | `-c general.regex-style-search=<value>` | Not Available |

!!! important
    At this time, `regex-style-search` is **disabled** by default, but it will be **enabled** by default in the future.
    


Gitlint will log a warning when you're using a rule that uses a custom regex and this option is not enabled:

```plain
WARNING: I1 - ignore-by-title: gitlint will be switching from using Python regex 'match' (match beginning) to
'search' (match anywhere) semantics. Please review your ignore-by-title.regex option accordingly.
To remove this warning, set general.regex-style-search=True. 
More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
```

**If you don't use custom regexes, gitlint will not log a warning and no action is needed.**

**To remove the warning:** 

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).
2. Enable `regex-style-search` in your gitlint config:

    === ":octicons-file-code-16:  .gitlint"

        ```ini
        [general]
        regex-style-search=true
        ```

    === ":octicons-terminal-16:  CLI"

        ```sh
        gitlint -c general.regex-style-search=true
        ```

## ignore-stdin
[:octicons-tag-24: v0.12.0][v0.12.0]

Ignore any stdin data.

| Default value    | Type            | CLI flag         | Env var                |
| ---------------- | --------------- | ---------------- | ---------------------- |
| `#!python false` | `#!python bool` | `--ignore-stdin` | `GITLINT_IGNORE_STDIN` |


=== ":octicons-file-code-16:  .gitlint"

    ```ini
    [general]
    ignore-stdin=true
    ```

=== ":octicons-terminal-16:  CLI"
    
    ```sh
    gitlint --ignore-stdin
    gitlint -c general.ignore-stdin=true # different way of doing the same
    ```

=== ":material-application-variable-outline: Env var"
    
    ```sh
    GITLINT_IGNORE_STDIN=1 gitlint      
    ```


## ignore-merge-commits
[:octicons-tag-24: v0.7.0][v0.7.0]

Whether or not to ignore merge commits.

| Default value   | Type            | CLI flag                                  | Env var       |
| --------------- | --------------- |