@@ -12,7 +12,7 @@ def get_bash_script():
1212 version = PipService .get_version ()
1313 id = uuid .uuid4 ()
1414
15- PREPARE_COMMIT_MSG_BASH_SCRIPT = f"""#!/usr/bin/env bash
15+ PREPARE_COMMIT_MSG_BASH_SCRIPT = f"""#!/usr/bin/env bash
1616# This file was generated by git-ai-commit: https://github.com/the-cafe/git-ai-commit
1717# version: { version }
1818# hash: { id }
@@ -30,26 +30,29 @@ def get_bash_script():
3030"""
3131 return PREPARE_COMMIT_MSG_BASH_SCRIPT
3232
33+
3334def handle_setup_hook (hook_directory_path : str ):
3435 existing_hook_content = ""
3536 if os .path .exists (hook_directory_path ):
36- with open (hook_directory_path , 'r' ) as file :
37- existing_hook_content = file .read ()
37+ with open (hook_directory_path , "r" ) as file :
38+ existing_hook_content = file .read ()
3839
3940 if existing_hook_content == get_bash_script ():
4041 Logger ().log ("prepare-commit-msg hook already exists" )
4142 return
4243
4344 if existing_hook_content :
44- override_content = input (f"prepare-commit-msg hook already exists in { hook_directory_path } \n \n Would you like to overwrite it? (y/n): " )
45+ override_content = input (
46+ f"prepare-commit-msg hook already exists in { hook_directory_path } \n \n Would you like to overwrite it? (y/n): "
47+ )
4548
46- if override_content .lower () == 'n' :
47- return
48- elif override_content .lower () != 'y' :
49- Logger ().log ("Invalid input. Exiting." )
49+ if override_content .lower () == "n" :
50+ return
51+ elif override_content .lower () != "y" :
52+ Logger ().log ("Invalid input. Exiting." )
5053
5154 ## create the prepare-commit-msg file and write the hook code
52- with open (hook_directory_path , 'w' ) as file :
55+ with open (hook_directory_path , "w" ) as file :
5356 file .write (get_bash_script ())
5457
5558 # make the file executable
@@ -74,7 +77,9 @@ def setup_husky_git_hook():
7477 Logger ().log ("[Setup] Husky prepare-commit-msg hook" )
7578
7679 if not HuskyService .repo_has_husky_framework ():
77- Logger ().log ("Husky framework not found in the repository. Please install husky - https://typicode.github.io/husky/" )
80+ Logger ().log (
81+ "Husky framework not found in the repository. Please install husky - https://typicode.github.io/husky/"
82+ )
7883 return
7984
8085 file_path = HuskyService .get_husky_prepare_commit_msg_hook_path ()
@@ -95,6 +100,7 @@ def setup_git_hook():
95100
96101 return
97102
103+
98104def hook_handler (args ):
99105 if args .setup :
100106 setup_git_hook ()
0 commit comments