diff options
author | Joris Roovers <jroovers@cisco.com> | 2018-04-01 16:23:29 +0200 |
---|---|---|
committer | Joris Roovers <jroovers@cisco.com> | 2018-04-01 16:23:29 +0200 |
commit | 52dc67e751dbbaa66c455063c6fe4f2f86d668d4 (patch) | |
tree | 2ddebe945e6664f763283a3f3c6d4fc895d92c1a | |
parent | 7d447959e4220428d929c4aa1310675bb9e3bee1 (diff) |
Integration test + docs for ignore-by-title rule
Added integration tests and documentation for the new ignore-by-title rule.
Also added '--ignore-requires-python' to pip installs in run_tests.sh to
deal with some python 2.6 and 3.3 issues.
-rw-r--r-- | docs/index.md | 32 | ||||
-rw-r--r-- | examples/gitlint | 2 | ||||
-rw-r--r-- | gitlint/files/gitlint | 11 | ||||
-rw-r--r-- | qa/samples/config/ignore-release-commits | 3 | ||||
-rw-r--r-- | qa/test_commits.py | 30 | ||||
-rwxr-xr-x | run_tests.sh | 4 |
6 files changed, 77 insertions, 5 deletions
diff --git a/docs/index.md b/docs/index.md index 50f3354..25509f2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -38,6 +38,8 @@ gitlint cat examples/commit-message-1 | gitlint # or git log -1 --pretty=%B | gitlint +# Or read the commit-msg from a file, like so: +gitlint --msg-filename examples/commit-message-2 # To install a gitlint as a commit-msg git hook: gitlint install-hook @@ -175,8 +177,8 @@ Note that gitlint requires that you specify ```--pretty=%B``` (=only print the l future versions of gitlint might fix this and not require the ```--pretty``` argument. ## Linting a range of commits ## -_Experimental support introduced in gitlint v0.8.1, known issues:_ -_[#23](https://github.com/jorisroovers/gitlint/pull/23)_ + +_Introduced in gitlint v0.9.0 (experimental in v0.8.0)_ Gitlint allows users to commit a number of commits at once like so: @@ -236,6 +238,32 @@ In case you *do* want to lint these commit messages, you can disable this behavi general ```ignore-merge-commits```, ```ignore-fixup-commits``` or ```ignore-squash-commits``` option to ```false``` [using one of the various ways to configure gitlint](configuration.md). +## Ignoring commits ## +_Introduced in gitlint v0.10.0_ + +Gitlint allows you to ignore specific rules for specific commits. + +One way to do this, is to by [adding a gitline-ignore line to your commit message](configuration.md#commit-specific-config). + +If you have a case where you want to ignore a certain type of commits all-together, you can +use gitlint's *ignore* rules to do so. +Here's an example gitlint file that configures gitlint to ignore rules ```title-max-length``` and ```body-min-length``` +for all commits with a title starting with *"Release"*. + +```ini +[ignore-by-title] +# Match commit titles starting with Release +regex=^Release(.*) +ignore=title-max-length,body-min-length +# ignore all rules by setting ignore to 'all' +# ignore=all +``` + +!!! note + + Right now it's not possible to write user-defined ignore rules to handle more complex user-cases. + This is however something that we'd like to implement in a future version. If this is something you're interested in + please let us know by [opening an issue](https://github.com/jorisroovers/gitlint/issues). ## Exit codes ## Gitlint uses the exit code as a simple way to indicate the number of violations found. Some exit codes are used to indicate special errors as indicated in the table below. diff --git a/examples/gitlint b/examples/gitlint index fabef2a..9bfe68c 100644 --- a/examples/gitlint +++ b/examples/gitlint @@ -1,4 +1,6 @@ # All these sections are optional, edit this file as you like. +# 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 diff --git a/gitlint/files/gitlint b/gitlint/files/gitlint index b0ca63b..e678d04 100644 --- a/gitlint/files/gitlint +++ b/gitlint/files/gitlint @@ -61,4 +61,13 @@ # python like regex (https://docs.python.org/2/library/re.html) that the # commit author email address should be matched to # For example, use the following regex if you only want to allow email addresses from foo.com -# regex = "[^@]+@foo.com"
\ No newline at end of file +# regex=[^@]+@foo.com + +# [ignore-by-title] +# Ignore certain rules for commits of which the title matches a regex +# E.g. Match commit titles that start with "Release" +# regex=^Release(.*) +# +# Ignore certain rules, you can reference them by their id or by their full name +# Use 'all' to ignore all rules +# ignore=T1,body-min-length
\ No newline at end of file diff --git a/qa/samples/config/ignore-release-commits b/qa/samples/config/ignore-release-commits new file mode 100644 index 0000000..898e73f --- /dev/null +++ b/qa/samples/config/ignore-release-commits @@ -0,0 +1,3 @@ +[ignore-by-title] +regex=^Release(.*) +ignore=T5,T3
\ No newline at end of file diff --git a/qa/test_commits.py b/qa/test_commits.py index be0a8fd..0d306e1 100644 --- a/qa/test_commits.py +++ b/qa/test_commits.py @@ -73,3 +73,33 @@ class CommitsTests(BaseTestCase): ) self.assertEqual(output, expected) + + def test_ignore_commits(self): + """ Tests multiple commits of which some rules get igonored because of ignore-* rules """ + # Create repo and some commits + tmp_git_repo = self.create_tmp_git_repo() + self._create_simple_commit(u"Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo) + # Normally, this commit will give T3 (trailing-punctuation), T5 (WIP) and B5 (bod-too-short) violations + # But in this case only B5 because T3 and T5 are being ignored because of config + self._create_simple_commit(u"Release: WIP tïtle.\n\nShort", git_repo=tmp_git_repo) + # In the following 2 commits, the T3 violations are as normal + self._create_simple_commit(u"Sïmple title3.\n\nSimple bödy describing the commit3", git_repo=tmp_git_repo) + self._create_simple_commit(u"Sïmple title4.\n\nSimple bödy describing the commit4", git_repo=tmp_git_repo) + revlist = git("rev-list", "HEAD", _err_to_out=True, _cwd=tmp_git_repo).split() + + config_path = self.get_sample_path("config/ignore-release-commits") + output = gitlint("--commits", "HEAD", "--config", config_path, _cwd=tmp_git_repo, + _tty_in=False, _err_to_out=True, _ok_code=[4]) + + expected = ( + u"Commit {0}:\n".format(revlist[0][:10]) + + u"1: T3 Title has trailing punctuation (.): \"Sïmple title4.\"\n\n" + + u"Commit {0}:\n".format(revlist[1][:10]) + + u"1: T3 Title has trailing punctuation (.): \"Sïmple title3.\"\n\n" + + u"Commit {0}:\n".format(revlist[2][:10]) + + u"3: B5 Body message is too short (5<20): \"Short\"\n\n" + + u"Commit {0}:\n".format(revlist[3][:10]) + + u"1: T3 Title has trailing punctuation (.): \"Sïmple title.\"\n" + ) + + self.assertEqual(output, expected) diff --git a/run_tests.sh b/run_tests.sh index a5af485..38fd12e 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -264,8 +264,8 @@ install_virtualenv(){ virtualenv -p "$python_binary" "$venv_name" source "${venv_name}/bin/activate" easy_install -U pip - pip install -r requirements.txt - pip install -r test-requirements.txt + pip install --ignore-requires-python -r requirements.txt + pip install --ignore-requires-python -r test-requirements.txt deactivate 2> /dev/null } |