@@ -34,6 +34,18 @@ class RepoFileMover:
3434 GIT_EXE = 'git'
3535 FRAMEWORK_DEFAULT_BASE_BRANCH = 'main'
3636
37+ FRAMEWORK_SIDE_TEMPLATE = '''Move files from into the framework
38+
39+ # This will be the commit message for the commit in the framework
40+ # repository that adds the files that were moved.
41+ '''
42+
43+ MBEDTLS_SIDE_TEMPLATE = '''Move files out of Mbed TLS
44+
45+ # This will be the commit message for the commit in the Mbed TLS
46+ # repository that removes the files that were moved.
47+ '''
48+
3749 def __init__ (self , source_repo : str , dest_repo : str ,
3850 source_branch_name : str , dest_branch_name : str ,
3951 file_map : Dict [str , str ],
@@ -59,6 +71,14 @@ class RepoFileMover:
5971 cmd = [self .GIT_EXE ] + git_cmd
6072 return subprocess .check_output (cmd , ** kwargs )
6173
74+ def run_git_interactive (self , git_cmd : List [str ], ** kwargs ) -> int :
75+ """Run a git command that may interact with the user and return
76+ its return code."""
77+ if 'universal_newlines' not in kwargs :
78+ kwargs ['universal_newlines' ] = True
79+ cmd = [self .GIT_EXE ] + git_cmd
80+ return subprocess .run (cmd , ** kwargs ).returncode
81+
6282 def add_file_move (self , src_path : str , dst_path : str ) -> None :
6383 """Move file at relative path src_path in the source repo to dst_path
6484 in the destination repo"""
@@ -117,6 +137,18 @@ class RepoFileMover:
117137 # Make all required directories
118138 os .makedirs (dirs , exist_ok = True )
119139
140+ def commit_interactively_with_template (self , commit_template : str ,
141+ * extra_flags ) -> None :
142+ template_name = 'commit-msg-template-{pid}' .format (pid = os .getpid ())
143+
144+ with open (template_name , 'w' ) as template_file :
145+ template_file .write (commit_template )
146+
147+ self .run_git_interactive (['commit' , '-t' , template_name ] + list (extra_flags ))
148+
149+ os .remove (template_name )
150+
151+
120152 def create_dest_repo_branch (self ):
121153 """Create the branch containing the moved files only"""
122154
@@ -149,8 +181,7 @@ class RepoFileMover:
149181 self .run_git (['mv' , f , self ._file_map [f ]])
150182
151183 # Commit the result
152- commit_message = "Move some files to framework repository"
153- self .run_git (['commit' , '-asm' , commit_message ])
184+ self .commit_interactively_with_template (self .FRAMEWORK_SIDE_TEMPLATE , '-as' )
154185
155186 def create_src_repo_branch (self ):
156187 """Create the branch deleting the moved files"""
@@ -167,8 +198,7 @@ class RepoFileMover:
167198 self .run_git (['rm' , f ])
168199
169200 # Commit the result
170- commit_message = "Move some files to framework repository"
171- self .run_git (['commit' , '-asm' , commit_message ])
201+ self .commit_interactively_with_template (self .MBEDTLS_SIDE_TEMPLATE , '-as' )
172202
173203 def resolve_deletion_conflicts (self ):
174204 file_statuses = self .run_git (['status' , '--porcelain' ])
0 commit comments