2015-10-05 20:16:52 +00:00
|
|
|
# git-validation
|
|
|
|
|
2016-04-05 14:06:48 +00:00
|
|
|
A way to do validation on git commits.
|
2021-05-14 18:43:53 +00:00
|
|
|
[![Travis Status](https://travis-ci.org/vbatts/git-validation.svg?branch=master)](https://travis-ci.org/vbatts/git-validation)
|
|
|
|
[![GithubActions Status](https://github.com/vbatts/git-validation/actions/workflows/go.yml/badge.svg)](https://github.com/vbatts/git-validation/actions/workflows/go.yml)
|
2015-10-05 20:16:52 +00:00
|
|
|
|
2015-10-06 14:47:00 +00:00
|
|
|
## install
|
2015-10-05 20:16:52 +00:00
|
|
|
|
2022-09-14 13:33:15 +00:00
|
|
|
```shell
|
|
|
|
go install github.com/vbatts/git-validation@latest
|
2015-10-06 14:47:00 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## usage
|
|
|
|
|
2015-10-06 14:51:22 +00:00
|
|
|
The flags
|
2022-09-14 13:33:15 +00:00
|
|
|
|
|
|
|
```shell
|
2015-10-06 14:51:22 +00:00
|
|
|
vbatts@valse ~/src/vb/git-validation (master *) $ git-validation -h
|
|
|
|
Usage of git-validation:
|
|
|
|
-D debug output
|
|
|
|
-d string
|
|
|
|
git directory to validate from (default ".")
|
|
|
|
-list-rules
|
|
|
|
list the rules registered
|
|
|
|
-range string
|
|
|
|
use this commit range instead
|
|
|
|
-run string
|
|
|
|
comma delimited list of rules to run. Defaults to all.
|
|
|
|
-v verbose
|
|
|
|
```
|
|
|
|
|
2016-04-05 14:06:48 +00:00
|
|
|
The entire default rule set is run by default:
|
2022-09-14 13:33:15 +00:00
|
|
|
|
|
|
|
```shell
|
2015-10-06 14:51:22 +00:00
|
|
|
vbatts@valse ~/src/vb/git-validation (master) $ git-validation -list-rules
|
2017-10-09 19:49:59 +00:00
|
|
|
"dangling-whitespace" -- checking the presence of dangling whitespaces on line endings
|
2015-10-06 14:51:22 +00:00
|
|
|
"DCO" -- makes sure the commits are signed
|
2017-10-09 19:49:59 +00:00
|
|
|
"message_regexp" -- checks the commit message for a user provided regular expression
|
2015-10-06 14:51:22 +00:00
|
|
|
"short-subject" -- commit subjects are strictly less than 90 (github ellipsis length)
|
|
|
|
```
|
|
|
|
|
2016-04-05 14:06:48 +00:00
|
|
|
Or, specify comma-delimited rules to run:
|
2022-09-14 13:33:15 +00:00
|
|
|
|
|
|
|
```shell
|
2015-10-06 14:51:22 +00:00
|
|
|
vbatts@valse ~/src/vb/git-validation (master) $ git-validation -run DCO,short-subject
|
|
|
|
* b243ca4 "README: adding install and usage" ... PASS
|
2015-10-06 14:47:00 +00:00
|
|
|
* d614ccf "*: run tests in a runner" ... PASS
|
|
|
|
* b9413c6 "shortsubject: add a subject length check" ... PASS
|
|
|
|
* 5e74abd "*: comments and golint" ... PASS
|
|
|
|
* 07a982f "git: add verbose output of the commands run" ... PASS
|
|
|
|
* 03bda4b "main: add filtering of rules to run" ... PASS
|
|
|
|
* c10ba9c "Initial commit" ... PASS
|
2015-10-06 14:51:22 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Verbosity shows each rule's output:
|
2022-09-14 13:33:15 +00:00
|
|
|
|
|
|
|
```shell
|
2015-10-06 14:47:00 +00:00
|
|
|
vbatts@valse ~/src/vb/git-validation (master) $ git-validation -v
|
|
|
|
* d614ccf "*: run tests in a runner" ... PASS
|
|
|
|
- PASS - has a valid DCO
|
|
|
|
- PASS - commit subject is 72 characters or less! *yay*
|
|
|
|
* b9413c6 "shortsubject: add a subject length check" ... PASS
|
|
|
|
- PASS - has a valid DCO
|
|
|
|
- PASS - commit subject is 72 characters or less! *yay*
|
|
|
|
* 5e74abd "*: comments and golint" ... PASS
|
|
|
|
- PASS - has a valid DCO
|
|
|
|
- PASS - commit subject is 72 characters or less! *yay*
|
|
|
|
* 07a982f "git: add verbose output of the commands run" ... PASS
|
|
|
|
- PASS - has a valid DCO
|
|
|
|
- PASS - commit subject is 72 characters or less! *yay*
|
|
|
|
* 03bda4b "main: add filtering of rules to run" ... PASS
|
|
|
|
- PASS - has a valid DCO
|
|
|
|
- PASS - commit subject is 72 characters or less! *yay*
|
|
|
|
* c10ba9c "Initial commit" ... PASS
|
|
|
|
- PASS - has a valid DCO
|
|
|
|
- PASS - commit subject is 72 characters or less! *yay*
|
|
|
|
```
|
|
|
|
|
|
|
|
Here's a failure:
|
2022-09-14 13:33:15 +00:00
|
|
|
|
|
|
|
```shell
|
2015-10-06 14:47:00 +00:00
|
|
|
vbatts@valse ~/src/vb/git-validation (master) $ git-validation
|
|
|
|
* 49f51a8 "README: adding install and usage" ... FAIL
|
|
|
|
- FAIL - does not have a valid DCO
|
|
|
|
* d614ccf "*: run tests in a runner" ... PASS
|
|
|
|
* b9413c6 "shortsubject: add a subject length check" ... PASS
|
|
|
|
* 5e74abd "*: comments and golint" ... PASS
|
|
|
|
* 07a982f "git: add verbose output of the commands run" ... PASS
|
|
|
|
* 03bda4b "main: add filtering of rules to run" ... PASS
|
|
|
|
* c10ba9c "Initial commit" ... PASS
|
|
|
|
1 issues to fix
|
|
|
|
vbatts@valse ~/src/vb/git-validation (master) $ echo $?
|
|
|
|
1
|
|
|
|
```
|
2015-10-06 14:55:42 +00:00
|
|
|
|
2017-04-27 14:29:28 +00:00
|
|
|
Excluding paths that are out of the scope of your project:
|
2022-09-14 13:33:15 +00:00
|
|
|
|
|
|
|
```shell
|
2018-03-07 00:54:54 +00:00
|
|
|
vbatts@valse ~/src/vb/git-validation (master) $ GIT_CHECK_EXCLUDE="./vendor:./git/testdata" git-validation -q -run dangling-whitespace
|
2017-04-27 14:29:28 +00:00
|
|
|
...
|
|
|
|
```
|
|
|
|
|
2022-09-14 13:33:15 +00:00
|
|
|
using the `GIT_CHECK_EXCLUDE` environment variable. Multiple paths should be separated by colon(`:`)
|
2017-10-09 19:49:59 +00:00
|
|
|
|
2023-03-15 01:45:05 +00:00
|
|
|
## contributing
|
|
|
|
|
|
|
|
When making a change, verify it with:
|
|
|
|
|
|
|
|
```shell
|
2023-03-15 02:11:02 +00:00
|
|
|
go run mage.go lint vet build test
|
2023-03-15 01:45:05 +00:00
|
|
|
```
|
|
|
|
|
2015-10-06 14:55:42 +00:00
|
|
|
## Rules
|
|
|
|
|
|
|
|
Default rules are added by registering them to the `validate` package.
|
|
|
|
Usually by putting them in their own package.
|
|
|
|
See [`./rules/`](./rules/).
|
|
|
|
Feel free to contribute more.
|
|
|
|
|
2016-04-05 14:06:48 +00:00
|
|
|
Otherwise, by using `validate` package API directly, rules can be handed directly to the `validate.Runner`.
|