| 187 | |
| 188 | |
| 189 | def _check_args_length(hook_type: str, args: Sequence[str]) -> None: |
| 190 | if hook_type == 'prepare-commit-msg': |
| 191 | if len(args) < 1 or len(args) > 3: |
| 192 | raise SystemExit( |
| 193 | f'hook-impl for {hook_type} expected 1, 2, or 3 arguments ' |
| 194 | f'but got {len(args)}: {args}', |
| 195 | ) |
| 196 | elif hook_type == 'pre-rebase': |
| 197 | if len(args) < 1 or len(args) > 2: |
| 198 | raise SystemExit( |
| 199 | f'hook-impl for {hook_type} expected 1 or 2 arguments ' |
| 200 | f'but got {len(args)}: {args}', |
| 201 | ) |
| 202 | elif hook_type in _EXPECTED_ARG_LENGTH_BY_HOOK: |
| 203 | expected = _EXPECTED_ARG_LENGTH_BY_HOOK[hook_type] |
| 204 | if len(args) != expected: |
| 205 | arguments_s = 'argument' if expected == 1 else 'arguments' |
| 206 | raise SystemExit( |
| 207 | f'hook-impl for {hook_type} expected {expected} {arguments_s} ' |
| 208 | f'but got {len(args)}: {args}', |
| 209 | ) |
| 210 | else: |
| 211 | raise AssertionError(f'unexpected hook type: {hook_type}') |
| 212 | |
| 213 | |
| 214 | def _run_ns( |