@@ -97,8 +97,9 @@ def proc_pipeline(name):
9797 try :
9898 lines = file .read ()
9999 except UnicodeDecodeError :
100- print ("Error: " + name + " contains characters not in UTF-8. "
101- "Should this be considered a generated file?" )
100+ print (
101+ f"error: { name } contains characters not in UTF-8. Should this be considered a generated file?"
102+ )
102103 return False
103104
104105 # The success flag is aggregated across multiple file processing results
@@ -311,9 +312,25 @@ def main():
311312 # Don't check for changes in or run tasks on ignored files
312313 files = filter_ignored_files (files )
313314
315+ # Determine name of main branch for generated file comparisons
316+ branch_options = ["master" , "main" ]
317+ main_branch = ""
318+ for branch in branch_options :
319+ proc = subprocess .run (["git" , "rev-parse" , "-q" , "--verify" , branch ],
320+ stdout = subprocess .DEVNULL )
321+ if proc .returncode == 0 :
322+ main_branch = branch
323+ break
324+
325+ if not main_branch :
326+ print (
327+ f"error: One of the following branches is required for generated file comparisons, but none exist: { branch_options } ."
328+ )
329+ sys .exit (1 )
330+
314331 # Create list of all changed files
315332 output_list = subprocess .check_output (
316- ["git" , "diff" , "--name-only" , "master" ], encoding = "ascii" ).split ()
333+ ["git" , "diff" , "--name-only" , main_branch ], encoding = "ascii" ).split ()
317334 changed_file_list = [
318335 root_path + os .sep + line .strip () for line in output_list
319336 ]
0 commit comments