@@ -47,7 +47,9 @@ def get_repo_path(self) -> Path:
4747
4848 def run_cmd (self , args : list [str ], check : bool = True ) -> str :
4949 git_cmd = ["git" , "-C" , str (self .repo_path )] + args
50+ logger .debug ("Running git command: %s" , git_cmd )
5051 git_process = subprocess .run (git_cmd , check = check , capture_output = True , text = True )
52+ logger .debug ("Stdout:\n %s\n Stderr:\n %s" , git_process .stdout , git_process .stderr )
5153 return git_process .stdout
5254
5355
@@ -79,9 +81,12 @@ def prefix_current_commit_message(git_repo: Git) -> None:
7981 git_repo .run_cmd (["commit" , "--amend" , "--message=" + commit_msg ])
8082
8183
82- def merge_commit (git_repo : Git , to_branch : str , commit_hash : str , ignored_paths : list [str ], dry_run : bool ) -> None :
84+ def merge_commit (git_repo : Git , to_branch : str , commit_hash : str , ignored_paths : list [str ], dry_run : bool , verbose : bool ) -> None :
8385 logger .info ("Merging commit %s into %s" , commit_hash , to_branch )
8486 git_repo .run_cmd (["switch" , to_branch ])
87+ if verbose :
88+ current_head = git_repo .run_cmd (["log" , "--no-walk" , "HEAD" , "--pretty=reference" ])
89+ logger .debug ("Current HEAD of %s is %s" , to_branch , current_head )
8590 git_repo .run_cmd (["merge" , commit_hash , "--no-commit" , "--no-ff" ], check = False )
8691 restore_changes_to_ignored_files (git_repo , ignored_paths )
8792 if has_unresolved_conflicts (git_repo ):
@@ -90,6 +95,9 @@ def merge_commit(git_repo: Git, to_branch: str, commit_hash: str, ignored_paths:
9095 raise MergeConflictError (commit_hash )
9196 git_repo .run_cmd (["commit" , "--reuse-message" , commit_hash ])
9297 prefix_current_commit_message (git_repo )
98+ if verbose :
99+ merge_reference = git_repo .run_cmd (["log" , "--no-walk" , "HEAD" , "--pretty=reference" ])
100+ logger .debug ("Merge commit finalized: %s" , merge_reference )
93101 if dry_run :
94102 logger .info ("Dry run. Skipping push into remote repository." )
95103 else :
@@ -180,9 +188,17 @@ def main():
180188 action = "store_true" ,
181189 help = "Process changes locally, but don't merge them into the remote repository and don't create PRs" ,
182190 )
191+ arg_parser .add_argument (
192+ "--verbose" ,
193+ action = "store_true" ,
194+ help = "Print verbose log messages during automerge run" ,
195+ )
183196
184197 args = arg_parser .parse_args ()
185198
199+ if args .verbose :
200+ logger .setLevel (logging .DEBUG )
201+
186202 try :
187203 if pr_exist_for_label (args .project_name , MERGE_CONFLICT_LABEL ):
188204 logger .error ("There are pending automerge PRs. Cannot continue." )
@@ -196,7 +212,7 @@ def main():
196212
197213 merge_commits = get_merge_commit_list (git_repo , args .from_branch , args .to_branch )
198214 for commit_hash in merge_commits :
199- merge_commit (git_repo , args .to_branch , commit_hash , ignored_paths , args .dry_run )
215+ merge_commit (git_repo , args .to_branch , commit_hash , ignored_paths , args .dry_run , args . verbose )
200216 except MergeConflictError as conflict :
201217 process_conflict (
202218 git_repo ,
0 commit comments