Skip to content

Commit

Permalink
Fix + integration tests + docs for --msg-filename
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jroovers-cisco committed Mar 30, 2018
1 parent 1c36d7d commit 63109d7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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}"
Expand Down
35 changes: 18 additions & 17 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 3 additions & 6 deletions gitlint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions gitlint/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ def test_from_filename(self):
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, _):
Expand Down
15 changes: 14 additions & 1 deletion qa/test_gitlint.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -129,3 +129,16 @@ def test_pipe_input(self):
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)
1 change: 0 additions & 1 deletion qa/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def setUp(self):
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):
Expand Down

0 comments on commit 63109d7

Please # to comment.