diff --git a/docs/tutorials/auto_prepare_commit_message.md b/docs/tutorials/auto_prepare_commit_message.md index 3011142679..7e8295b7c8 100644 --- a/docs/tutorials/auto_prepare_commit_message.md +++ b/docs/tutorials/auto_prepare_commit_message.md @@ -25,7 +25,7 @@ commitizen and use the generated commit message for the commit. ## Installation -Copy the hooks from [here](https://github.com/commitizen-tools/hooks) into the `.git/hooks` folder and make them +Copy the hooks from [here](https://github.com/commitizen-tools/commitizen/tree/master/hooks) into the `.git/hooks` folder and make them executable by running the following commands from the root of your Git repository: ```bash diff --git a/hooks/post-commit.py b/hooks/post-commit.py index 6444e5ca84..c7dea825bd 100755 --- a/hooks/post-commit.py +++ b/hooks/post-commit.py @@ -8,7 +8,7 @@ exit(1) -def post_commit(): +def post_commit() -> None: backup_file = Path(get_backup_file_path()) # remove backup file if it exists @@ -17,4 +17,5 @@ def post_commit(): if __name__ == "__main__": - exit(post_commit()) + post_commit() + exit(0) diff --git a/hooks/prepare-commit-msg.py b/hooks/prepare-commit-msg.py index d1ccf169cf..e666fa673b 100755 --- a/hooks/prepare-commit-msg.py +++ b/hooks/prepare-commit-msg.py @@ -13,22 +13,19 @@ exit(1) -def prepare_commit_msg(commit_msg_file: Path) -> int: +def prepare_commit_msg(commit_msg_file: str) -> int: # check if the commit message needs to be generated using commitizen - if ( - subprocess.run( - [ - "cz", - "check", - "--commit-msg-file", - commit_msg_file, - ], - capture_output=True, - ).returncode - != 0 - ): + 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]: ") @@ -54,6 +51,7 @@ def prepare_commit_msg(commit_msg_file: Path) -> int: # write message to backup file shutil.copyfile(commit_msg_file, backup_file) + return 0 if __name__ == "__main__":