Coverage for src/hooks/check_commitizen_branch.py: 0.00%
28 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-08 13:49 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-08 13:49 +0000
1#!/usr/bin/env python3
3# Standard libraries
4from os import environ
5from pathlib import Path
6import sys
7from sys import exit as sys_exit, path
9# Bind sources
10sys.dont_write_bytecode = True
11path.append(str(Path(__file__).resolve().parent.parent))
13# Components, pylint: disable=import-error,wrong-import-position
14from system.commands import Commands
16# Commitizen branch
17def commitizen_branch(
18 remote: str,
19 ignore_empty: bool = False,
20) -> int:
22 # Prepare --no-raise option
23 no_raise: str = '3'
24 if ignore_empty:
25 no_raise += ',23'
27 # Check commitizen branch
28 return int(
29 Commands.exec('cz', [
30 '--no-raise',
31 no_raise,
32 'check',
33 '--rev-range',
34 f'{remote}/HEAD..HEAD',
35 ]))
37# Update remote head
38def git_update_remote_head(remote: str) -> bool:
40 # Fetch remote branches
41 Commands.run('git', [
42 'fetch',
43 f'{remote}',
44 ])
46 # Update remote head
47 return bool(Commands.run('git', [
48 'remote',
49 'set-head',
50 f'{remote}',
51 '-a',
52 ]))
54# Main, pylint: disable=too-many-branches,too-many-statements
55def main() -> None:
57 # Variables
58 remote: str = ''
59 result: int = 1
61 # Detect Git remote
62 print(environ)
63 if environ.get('PRE_COMMIT_REMOTE_NAME', ''):
64 remote = str(environ.get('PRE_COMMIT_REMOTE_NAME'))
65 else:
66 remote = 'origin'
68 # Check commitizen branch
69 result = commitizen_branch(remote)
71 # Update Git remote
72 if result == 23:
73 if git_update_remote_head(remote):
74 result = commitizen_branch(remote)
75 else:
76 result = 0
78 # Result
79 sys_exit(result)
81# Entrypoint
82if __name__ == '__main__': # pragma: no cover
83 main()