Adding upstream version 4.6.0+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
f3ad83a1a5
commit
167a3f8553
275 changed files with 30423 additions and 0 deletions
21
hooks/post-commit.py
Executable file
21
hooks/post-commit.py
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
from commitizen.cz.utils import get_backup_file_path
|
||||
except ImportError as error:
|
||||
print(f"could not import commitizen:\n{error}")
|
||||
exit(1)
|
||||
|
||||
|
||||
def post_commit() -> None:
|
||||
backup_file = Path(get_backup_file_path())
|
||||
|
||||
# remove backup file if it exists
|
||||
if backup_file.is_file():
|
||||
backup_file.unlink()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
post_commit()
|
||||
exit(0)
|
61
hooks/prepare-commit-msg.py
Executable file
61
hooks/prepare-commit-msg.py
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env python
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
try:
|
||||
from commitizen.cz.utils import get_backup_file_path
|
||||
except ImportError as error:
|
||||
print("could not import commitizen:")
|
||||
print(error)
|
||||
exit(1)
|
||||
|
||||
|
||||
def prepare_commit_msg(commit_msg_file: str) -> int:
|
||||
# check if the commit message needs to be generated using commitizen
|
||||
exit_code = subprocess.run(
|
||||
[
|
||||
"cz",
|
||||
"check",
|
||||
"--commit-msg-file",
|
||||
commit_msg_file,
|
||||
],
|
||||
capture_output=True,
|
||||
).returncode
|
||||
if exit_code != 0:
|
||||
backup_file = Path(get_backup_file_path())
|
||||
if backup_file.is_file():
|
||||
# confirm if commit message from backup file should be reused
|
||||
answer = input("retry with previous message? [y/N]: ")
|
||||
if answer.lower() == "y":
|
||||
shutil.copyfile(backup_file, commit_msg_file)
|
||||
return 0
|
||||
|
||||
# use commitizen to generate the commit message
|
||||
try:
|
||||
subprocess.run(
|
||||
[
|
||||
"cz",
|
||||
"commit",
|
||||
"--dry-run",
|
||||
"--write-message-to-file",
|
||||
commit_msg_file,
|
||||
],
|
||||
stdin=sys.stdin,
|
||||
stdout=sys.stdout,
|
||||
).check_returncode()
|
||||
except CalledProcessError as error:
|
||||
return error.returncode
|
||||
|
||||
# write message to backup file
|
||||
shutil.copyfile(commit_msg_file, backup_file)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# make hook interactive by attaching /dev/tty to stdin
|
||||
with open("/dev/tty") as tty:
|
||||
sys.stdin = tty
|
||||
exit(prepare_commit_msg(sys.argv[1]))
|
Loading…
Add table
Add a link
Reference in a new issue