From b8d423e7d13686d6627571d6c4adf12661d82147 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 13 Oct 2021 07:34:54 +0200 Subject: Adding upstream version 0.16.0. Signed-off-by: Daniel Baumann --- gitlint/__init__.py | 2 +- gitlint/cli.py | 62 +++++++++++++-------- gitlint/config.py | 14 +++++ gitlint/contrib/rules/conventional_commit.py | 17 +++--- gitlint/files/gitlint | 15 +++++ gitlint/git.py | 17 ++++-- gitlint/rules.py | 24 +++++++- gitlint/shell.py | 8 +-- gitlint/tests/base.py | 7 +++ gitlint/tests/cli/test_cli.py | 64 +++++++++++++++++++++- gitlint/tests/config/test_config.py | 7 ++- .../contrib/rules/test_conventional_commit.py | 28 ++++++++++ gitlint/tests/expected/cli/test_cli/test_contrib_1 | 1 - gitlint/tests/expected/cli/test_cli/test_debug_1 | 4 ++ .../cli/test_cli/test_input_stream_debug_2 | 4 ++ .../tests/expected/cli/test_cli/test_lint_commit_1 | 2 + .../cli/test_cli/test_lint_staged_msg_filename_2 | 4 ++ .../expected/cli/test_cli/test_lint_staged_stdin_2 | 4 ++ .../tests/expected/cli/test_cli/test_named_rules_2 | 4 ++ gitlint/tests/git/test_git_commit.py | 64 ++++++++++++++++++++-- gitlint/tests/rules/test_body_rules.py | 6 +- gitlint/tests/rules/test_configuration_rules.py | 33 +++++++++++ gitlint/tests/rules/test_title_rules.py | 2 +- gitlint/tests/rules/test_user_rules.py | 6 +- gitlint/tests/test_options.py | 2 +- 25 files changed, 339 insertions(+), 62 deletions(-) create mode 100644 gitlint/tests/expected/cli/test_cli/test_lint_commit_1 (limited to 'gitlint') diff --git a/gitlint/__init__.py b/gitlint/__init__.py index 903e77c..5a313cc 100644 --- a/gitlint/__init__.py +++ b/gitlint/__init__.py @@ -1 +1 @@ -__version__ = "0.15.1" +__version__ = "0.16.0" diff --git a/gitlint/cli.py b/gitlint/cli.py index 9b16d47..19676b3 100644 --- a/gitlint/cli.py +++ b/gitlint/cli.py @@ -18,6 +18,7 @@ from gitlint.utils import LOG_FORMAT from gitlint.exception import GitlintError # Error codes +GITLINT_SUCCESS = 0 MAX_VIOLATION_ERROR_CODE = 252 USAGE_ERROR_CODE = 253 GIT_CONTEXT_ERROR_CODE = 254 @@ -61,7 +62,8 @@ def log_system_info(): def build_config( # pylint: disable=too-many-arguments - target, config_path, c, extra_path, ignore, contrib, ignore_stdin, staged, verbose, silent, debug + target, config_path, c, extra_path, ignore, contrib, ignore_stdin, staged, fail_without_commits, verbose, + silent, debug ): """ Creates a LintConfig object based on a set of commandline parameters. """ config_builder = LintConfigBuilder() @@ -102,6 +104,9 @@ def build_config( # pylint: disable=too-many-arguments if staged: config_builder.set_option('general', 'staged', staged) + if fail_without_commits: + config_builder.set_option('general', 'fail-without-commits', fail_without_commits) + config = config_builder.build() return config, config_builder @@ -139,7 +144,7 @@ def get_stdin_data(): return False -def build_git_context(lint_config, msg_filename, refspec): +def build_git_context(lint_config, msg_filename, commit_hash, refspec): """ Builds a git context based on passed parameters and order of precedence """ # Determine which GitContext method to use if a custom message is passed @@ -168,7 +173,11 @@ def build_git_context(lint_config, msg_filename, refspec): # 3. Fallback to reading from local repository LOG.debug("No --msg-filename flag, no or empty data passed to stdin. Using the local repo.") - return GitContext.from_local_repository(lint_config.target, refspec) + + if commit_hash and refspec: + raise GitLintUsageError("--commit and --commits are mutually exclusive, use one or the other.") + + return GitContext.from_local_repository(lint_config.target, refspec=refspec, commit_hash=commit_hash) def handle_gitlint_error(ctx, exc): @@ -187,9 +196,10 @@ def handle_gitlint_error(ctx, exc): class ContextObj: """ Simple class to hold data that is passed between Click commands via the Click context. """ - def __init__(self, config, config_builder, refspec, msg_filename, gitcontext=None): + def __init__(self, config, config_builder, commit_hash, refspec, msg_filename, gitcontext=None): self.config = config self.config_builder = config_builder + self.commit_hash = commit_hash self.refspec = refspec self.msg_filename = msg_filename self.gitcontext = gitcontext @@ -205,6 +215,7 @@ class ContextObj: @click.option('-c', multiple=True, help="Config flags in format .