diff options
author | Joris Roovers <jroovers@cisco.com> | 2018-03-30 13:23:49 +0200 |
---|---|---|
committer | Joris Roovers <jroovers@cisco.com> | 2018-03-30 13:23:49 +0200 |
commit | 63109d73faab6049b7c5579affcec9dc5e327574 (patch) | |
tree | 58bb46347a4de45cf2fcabfb296dbe12dccb41b1 | |
parent | 1c36d7d939b7f65cc0757067c20115d056e4b01f (diff) |
Fix + integration tests + docs for --msg-filename
- Fixed an issue with unicode for --msg-filename (this is why the integration
tests failed).
- Added more specific integration tests for --msg-filename (currently it was
tested more implicitely through the hook tests).
- Update docs with info on --msg-filename
- Also updated Vagrantfile to xenial64 and fixed some related python
installation issues
-rw-r--r-- | Vagrantfile | 6 | ||||
-rw-r--r-- | docs/index.md | 35 | ||||
-rw-r--r-- | gitlint/cli.py | 9 | ||||
-rw-r--r-- | gitlint/tests/test_cli.py | 8 | ||||
-rw-r--r-- | qa/test_gitlint.py | 15 | ||||
-rw-r--r-- | qa/test_hooks.py | 1 |
6 files changed, 42 insertions, 32 deletions
diff --git a/Vagrantfile b/Vagrantfile index c787257..5a3cf75 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,8 +7,8 @@ INSTALL_DEPS=<<EOF cd /vagrant sudo add-apt-repository -y ppa:fkrull/deadsnakes sudo apt-get update -sudo apt-get install -y python2.6-dev python2.7-dev python3.3-dev python3.4-dev python3.5-dev python3.6-dev -sudo apt-get install -y python-virtualenv git ipython python3-pip silversearcher-ag +sudo apt-get install -y --allow-unauthenticated python2.6-dev python2.7-dev python3.3-dev python3.4-dev python3.5-dev python3.6-dev +sudo apt-get install -y python-virtualenv git ipython python-pip python3-pip silversearcher-ag sudo pip3 install virtualenv ./run_tests.sh --uninstall --envs all @@ -20,7 +20,7 @@ EOF Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.vm.box = "ubuntu/trusty64" + config.vm.box = "ubuntu/xenial64" config.vm.define "dev" do |dev| dev.vm.provision "shell", inline: "#{INSTALL_DEPS}" diff --git a/docs/index.md b/docs/index.md index 1ebdd6b..50f3354 100644 --- a/docs/index.md +++ b/docs/index.md @@ -89,23 +89,24 @@ Usage: gitlint [OPTIONS] COMMAND [ARGS]... Git lint tool, checks your git commit messages for styling issues Options: - --target DIRECTORY Path of the target git repository. [default: current - working directory] - -C, --config PATH Config file location [default: .gitlint] - -c TEXT Config flags in format <rule>.<option>=<value> (e.g.: - -c T1.line-length=80). Flag can be used multiple - times to set multiple config values. - --commits TEXT The range of commits to lint. [default: HEAD] - -e, --extra-path PATH Path to a directory or python module with extra user- - defined rules - --ignore TEXT Ignore rules (comma-separated by id or name). - -v, --verbose Verbosity, more v's for more verbose output (e.g.: - -v, -vv, -vvv). [default: -vvv] - -s, --silent Silent mode (no output). Takes precedence over -v, - -vv, -vvv. - -d, --debug Enable debugging output. - --version Show the version and exit. - --help Show this message and exit. + --target DIRECTORY Path of the target git repository. [default: + current working directory] + -C, --config PATH Config file location [default: .gitlint] + -c TEXT Config flags in format <rule>.<option>=<value> + (e.g.: -c T1.line-length=80). Flag can be used + multiple times to set multiple config values. + --commits TEXT The range of commits to lint. [default: HEAD] + -e, --extra-path PATH Path to a directory or python module with extra + user-defined rules + --ignore TEXT Ignore rules (comma-separated by id or name). + --msg-filename FILENAME Path to a file containing a commit-msg + -v, --verbose Verbosity, more v's for more verbose output (e.g.: + -v, -vv, -vvv). [default: -vvv] + -s, --silent Silent mode (no output). Takes precedence over -v, + -vv, -vvv. + -d, --debug Enable debugging output. + --version Show the version and exit. + --help Show this message and exit. Commands: generate-config Generates a sample gitlint config file. diff --git a/gitlint/cli.py b/gitlint/cli.py index 9a0a09a..acb37a9 100644 --- a/gitlint/cli.py +++ b/gitlint/cli.py @@ -118,17 +118,14 @@ def stdin_has_data(): @click.option('-e', '--extra-path', help="Path to a directory or python module with extra user-defined rules", type=click.Path(exists=True, resolve_path=True, readable=True)) @click.option('--ignore', default="", help="Ignore rules (comma-separated by id or name).") -@click.option( - '--msg-filename', type=click.File(), - help='Path to a file containing a commit-msg', -) +@click.option('--msg-filename', type=click.File(), help="Path to a file containing a commit-msg.") @click.option('-v', '--verbose', count=True, default=0, help="Verbosity, more v's for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv]", ) @click.option('-s', '--silent', help="Silent mode (no output). Takes precedence over -v, -vv, -vvv.", is_flag=True) @click.option('-d', '--debug', help="Enable debugging output.", is_flag=True) @click.version_option(version=gitlint.__version__) @click.pass_context -def cli( +def cli( # pylint: disable=too-many-arguments ctx, target, config, c, commits, extra_path, ignore, msg_filename, verbose, silent, debug, ): @@ -166,7 +163,7 @@ def lint(ctx): # If we get data via stdin, then let's consider that our commit message, otherwise parse it from the local git repo. if msg_filename: - gitcontext = GitContext.from_commit_msg(msg_filename.read()) + gitcontext = GitContext.from_commit_msg(ustr(msg_filename.read())) elif stdin_has_data(): stdin_str = ustr(sys.stdin.read()) gitcontext = GitContext.from_commit_msg(stdin_str) diff --git a/gitlint/tests/test_cli.py b/gitlint/tests/test_cli.py index 75a0a66..a2b4658 100644 --- a/gitlint/tests/test_cli.py +++ b/gitlint/tests/test_cli.py @@ -154,16 +154,16 @@ class CLITests(BaseTestCase): expected_output = u"3: B6 Body message is missing\n" with tempdir() as tmpdir: - msg_filename = os.path.join(tmpdir, 'msg') + msg_filename = os.path.join(tmpdir, "msg") with open(msg_filename, 'w') as f: - f.write('Commit title\n') + f.write("Commït title\n") with patch('gitlint.display.stderr', new=StringIO()) as stderr: - args = ['--msg-filename', msg_filename] + args = ["--msg-filename", msg_filename] result = self.cli.invoke(cli.cli, args) self.assertEqual(stderr.getvalue(), expected_output) self.assertEqual(result.exit_code, 1) - self.assertEqual(result.output, '') + self.assertEqual(result.output, "") @patch('gitlint.cli.stdin_has_data', return_value=True) def test_silent_mode(self, _): diff --git a/qa/test_gitlint.py b/qa/test_gitlint.py index 7bf8ff1..d6a80ae 100644 --- a/qa/test_gitlint.py +++ b/qa/test_gitlint.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- - +from datetime import datetime import os from sh import git, gitlint, echo # pylint: disable=no-name-in-module from qa.base import BaseTestCase @@ -129,3 +129,16 @@ class IntegrationTests(BaseTestCase): u"3: B6 Body message is missing\n" self.assertEqual(output, expected) + + def test_from_file(self): + tmp_commit_msg_file = os.path.realpath("/tmp/commitmsg-%s" % datetime.now().strftime("%Y%m%d-%H%M%S")) + with open(tmp_commit_msg_file, "w") as f: + f.write("WIP: msg-fïlename test.") + + output = gitlint("--msg-filename", tmp_commit_msg_file, _tty_in=False, _err_to_out=True, _ok_code=[3]) + + expected = u"1: T3 Title has trailing punctuation (.): \"WIP: msg-fïlename test.\"\n" + \ + u"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: msg-fïlename test.\"\n" + \ + u"3: B6 Body message is missing\n" + + self.assertEqual(output, expected) diff --git a/qa/test_hooks.py b/qa/test_hooks.py index 714874a..8f8fb5a 100644 --- a/qa/test_hooks.py +++ b/qa/test_hooks.py @@ -24,7 +24,6 @@ class HookTests(BaseTestCase): output_installed = gitlint("install-hook", _cwd=self.tmp_git_repo) expected_installed = u"Successfully installed gitlint commit-msg hook in %s/.git/hooks/commit-msg\n" % \ self.tmp_git_repo - self.assertEqual(output_installed, expected_installed) def tearDown(self): |