Initial check command. Args: config: The config object required for the command to perform its action arguments: All the flags provided by the user cwd: Current work directory
(self, config: BaseConfig, arguments: CheckArgs, *args: object)
| 32 | """Check if the current commit msg matches the commitizen format.""" |
| 33 | |
| 34 | def __init__(self, config: BaseConfig, arguments: CheckArgs, *args: object) -> None: |
| 35 | """Initial check command. |
| 36 | |
| 37 | Args: |
| 38 | config: The config object required for the command to perform its action |
| 39 | arguments: All the flags provided by the user |
| 40 | cwd: Current work directory |
| 41 | """ |
| 42 | self.commit_msg_file = arguments.get("commit_msg_file") |
| 43 | self.commit_msg = arguments.get("message") |
| 44 | rev_range = arguments.get("rev_range") |
| 45 | # Expand env vars so the packaged ``commitizen-branch`` pre-push hook |
| 46 | # (which passes the literal ``$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REF``) |
| 47 | # keeps working after the ``shell=False`` switch in #1941. See #2003. |
| 48 | self.rev_range = os.path.expandvars(rev_range) if rev_range else rev_range |
| 49 | self.allow_abort = bool( |
| 50 | arguments.get("allow_abort", config.settings["allow_abort"]) |
| 51 | ) |
| 52 | |
| 53 | self.use_default_range = bool(arguments.get("use_default_range")) |
| 54 | self.max_msg_length = arguments.get( |
| 55 | "message_length_limit", config.settings.get("message_length_limit", 0) |
| 56 | ) |
| 57 | |
| 58 | # we need to distinguish between None and [], which is a valid value |
| 59 | allowed_prefixes = arguments.get("allowed_prefixes") |
| 60 | self.allowed_prefixes: list[str] = ( |
| 61 | allowed_prefixes |
| 62 | if allowed_prefixes is not None |
| 63 | else config.settings["allowed_prefixes"] |
| 64 | ) |
| 65 | |
| 66 | num_exclusive_args_provided = sum( |
| 67 | arg is not None |
| 68 | for arg in ( |
| 69 | self.commit_msg_file, |
| 70 | self.commit_msg, |
| 71 | self.rev_range, |
| 72 | ) |
| 73 | ) |
| 74 | |
| 75 | if num_exclusive_args_provided > 1: |
| 76 | raise InvalidCommandArgumentError( |
| 77 | "Only one of --rev-range, --message, and --commit-msg-file is permitted by check command! " |
| 78 | "See 'cz check -h' for more information" |
| 79 | ) |
| 80 | |
| 81 | if num_exclusive_args_provided == 0 and not sys.stdin.isatty(): |
| 82 | self.commit_msg = sys.stdin.read() |
| 83 | |
| 84 | self.config: BaseConfig = config |
| 85 | self.cz = factory.committer_factory(self.config) |
| 86 | |
| 87 | def __call__(self) -> None: |
| 88 | """Validate if commit messages follows the conventional pattern. |
nothing calls this directly
no test coverage detected