@@ -59,6 +59,7 @@ def search_command(terms: List[str]):
5959
6060from cfbs .cfbs_json import CFBSJson
6161from cfbs .cfbs_types import CFBSCommandExitCode , CFBSCommandGitResult
62+ from cfbs .masterfiles .analyze import most_relevant_version
6263from cfbs .updates import ModuleUpdates , update_module
6364from cfbs .utils import (
6465 CFBSNetworkError ,
@@ -1211,7 +1212,54 @@ def cfbs_convert_git_commit(
12111212 % masterfiles_version
12121213 )
12131214 print (
1214- "The next conversion step is to handle modified files and files from other versions of masterfiles."
1215+ "The next conversion step is to handle files from other versions of masterfiles."
1216+ )
1217+ if not prompt_user_yesno (non_interactive , "Do you want to continue?" ):
1218+ raise CFBSExitError ("User did not proceed, exiting." )
1219+ other_versions_files = analyzed_files .different
1220+ if len (other_versions_files ) > 0 :
1221+ print (
1222+ "The following files are taken from other versions of masterfiles (not %s):"
1223+ % masterfiles_version
1224+ )
1225+ other_versions_files = sorted (other_versions_files )
1226+ files_to_delete = []
1227+ for ov_file , other_versions in other_versions_files :
1228+ # don't display all versions (which is an arbitrarily-shaped sequence), instead choose the most relevant one:
1229+ relevant_version_text = most_relevant_version (
1230+ other_versions , masterfiles_version
1231+ )
1232+ if len (other_versions ) > 1 :
1233+ relevant_version_text += ", ..."
1234+ print ("- " , ov_file , "(%s)" % relevant_version_text )
1235+
1236+ files_to_delete .append (ov_file )
1237+ print (
1238+ "This usually indicates that someone made mistakes during past upgrades and it's recommended to delete these."
1239+ )
1240+ print (
1241+ "Your policy set will include the versions from %s instead (if they exist)."
1242+ % masterfiles_version
1243+ )
1244+ print (
1245+ "(Deletions will be visible in Git history so you can review or revert later)."
1246+ )
1247+ if prompt_user_yesno (
1248+ non_interactive , "Delete files from other versions? (Recommended)"
1249+ ):
1250+ print ("Deleting %s files." % len (files_to_delete ))
1251+ for file_d in files_to_delete :
1252+ rm (os .path .join (dir_name , file_d ))
1253+
1254+ print (
1255+ "Creating Git commit with deletion of policy files from other versions..."
1256+ )
1257+ cfbs_convert_git_commit ("Deleted policy files from other versions" )
1258+ print ("Done." , end = " " )
1259+ else :
1260+ print ("There are no files from other versions of masterfiles." )
1261+ print (
1262+ "The next conversion step is to handle files which have custom modifications."
12151263 )
12161264 print ("This is not implemented yet." )
12171265 return 0
0 commit comments