@@ -382,32 +382,45 @@ def add_footer(commit_msg):
382382 return commit_msg
383383
384384
385- def run ():
385+ def run (args ):
386386 # print(sys.version + "/n")
387+
387388 # Ensure the config directory exists
388389 os .makedirs (CONFIG_HOME_DIR , exist_ok = True )
389390
391+ commits_file_path = os .path .join (CONFIG_HOME_DIR , "commit_msg_history" )
392+ commit_msg_history = FileHistory (commits_file_path )
393+
390394 if WINDOW_WIDTH < 80 :
391395 Ansi .print_error (
392396 f"It is recommended you increase your window width ({ WINDOW_WIDTH } ) to at least 80."
393397 )
394398
395- print ("Starting a conventional git commit..." )
396- print (
397- Ansi .colour (
398- Ansi .fg .bright_red , "Tip: Press the up arrow key to recall history!"
399+ commit_msg = ""
400+ if len (args ) > 0 and args [0 ] == "retry" :
401+ args = args [1 :] # consume the first arg
402+ cm_histories_iter = commit_msg_history .load_history_strings ()
403+ last_commit_msg = ""
404+ for last_commit_msg in cm_histories_iter :
405+ pass
406+ commit_msg = last_commit_msg
407+
408+ if commit_msg == "" :
409+ print ("Starting a conventional git commit..." )
410+ print (
411+ Ansi .colour (
412+ Ansi .fg .bright_red , "Tip: Press the up arrow key to recall history!"
413+ )
399414 )
400- )
415+ commit_msg = add_type (commit_msg )
416+ commit_msg = add_scope (commit_msg )
417+ check_if_breaking_change ()
418+ commit_msg = add_description (commit_msg )
419+ commit_msg = add_body (commit_msg )
420+ commit_msg = add_footer (commit_msg )
421+ print ()
401422
402- commit_msg = ""
403- commit_msg = add_type (commit_msg )
404- commit_msg = add_scope (commit_msg )
405- check_if_breaking_change ()
406- commit_msg = add_description (commit_msg )
407- commit_msg = add_body (commit_msg )
408- commit_msg = add_footer (commit_msg )
409-
410- Ansi .print_ok ("\n This is your commit message:" )
423+ Ansi .print_ok ("This is your commit message:" )
411424 print ()
412425 print (commit_msg )
413426 print ()
@@ -416,8 +429,8 @@ def run():
416429
417430 # Extra command line arguments for git commit
418431 argv_passthrough = [] # by default add no extra arguments
419- if len (sys . argv ) > 1 :
420- argv_passthrough = sys . argv [1 :] # overwrite default list
432+ if len (args ) > 1 :
433+ argv_passthrough = args [1 :] # overwrite default list
421434 existing_args = " " .join (argv_passthrough )
422435 text = Ansi .colour (Ansi .fg .bright_yellow , "Extra args for git commit: " )
423436 extra_args_str = prompt (ANSI (text ), default = existing_args )
@@ -428,14 +441,14 @@ def run():
428441
429442 # Ask for confirmation to commit
430443 confirmation_validator = YesNoValidator (answer_required = True )
431-
432444 text = Ansi .b_yellow ("Do you want to make your commit? [y/n] " )
433445 confirm = prompt (ANSI (text ), validator = confirmation_validator ).lower ()
434446
435447 if confirm in confirmation_validator .confirmations :
436- print ( )
448+ commit_msg_history . store_string ( commit_msg )
437449 cmds = ["git" , "commit" , "-m" , commit_msg ] + argv_passthrough
438450 returncode = subprocess .run (cmds ).returncode
451+ print ()
439452 if returncode == 0 :
440453 Ansi .print_ok ("\n Commit has been made to conventional commits standards!" )
441454 else :
@@ -449,6 +462,7 @@ def run():
449462
450463def main ():
451464 try :
452- run ()
465+ # print(sys.argv)
466+ run (sys .argv [1 :])
453467 except KeyboardInterrupt :
454468 print ("\n Aborted." )
0 commit comments