#NEWLINE# def _fetch_project( self ) : #NEWLINE# #INDENT# '\n        Clones the project if necessary, fetches from the remote repo and resets to the requested commit\n        ' #NEWLINE# git_clone_fetch_depth_arg = '' #NEWLINE# if Configuration [ 'shallow_clones' ] : #NEWLINE# #INDENT# git_clone_fetch_depth_arg = '--depth=1' #NEWLINE# #UNINDENT# existing_repo_is_shallow = os . path . isfile ( os . path . join ( self . _repo_directory , '.git' , 'shallow' ) ) #NEWLINE# if ( ( not Configuration [ 'shallow_clones' ] ) and existing_repo_is_shallow and os . path . exists ( self . _repo_directory ) ) : #NEWLINE# #INDENT# shutil . rmtree ( self . _repo_directory ) #NEWLINE# fs . create_dir ( self . _repo_directory , self . DIRECTORY_PERMISSIONS ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . _execute_git_command_in_repo_and_raise_on_failure ( 'rev-parse' ) #NEWLINE# #UNINDENT# except RuntimeError : #NEWLINE# #INDENT# self . _logger . notice ( 'No valid repo in "{}". Cloning fresh from "{}".' , existing_repo_is_shallow . _repo_directory , self . _url ) #NEWLINE# self . _execute_git_command_in_repo_and_raise_on_failure ( git_command = 'clone {} {} {}' . format ( git_clone_fetch_depth_arg , self . _url , self . _repo_directory ) , error_msg = 'Could not clone repo.' ) #NEWLINE# #UNINDENT# self . _execute_git_command_in_repo_and_raise_on_failure ( git_command = 'fetch {} --update-head-ok {} {}' . format ( git_clone_fetch_depth_arg , self . _remote , self . _branch ) , error_msg = 'Could not fetch specified branch "{}" from remote "{}".' . format ( self . _branch , self . _remote ) ) #NEWLINE# fetch_head_hash = self . _execute_git_command_in_repo_and_raise_on_failure ( git_command = 'rev-parse FETCH_HEAD' , error_msg = 'Could not rev-parse FETCH_HEAD of {} to a commit hash.' . format ( self . _branch ) ) . strip ( ) #NEWLINE# self . _local_ref = 'refs/clusterrunner/{}' . format ( fetch_head_hash ) #NEWLINE# self . _execute_git_command_in_repo_and_raise_on_failure ( git_command = 'update-ref {} {}' . format ( self . _local_ref , fetch_head_hash ) , error_msg = 'Could not update local ref.' ) #NEWLINE# self . _execute_git_command_in_repo_and_raise_on_failure ( git_command = 'reset --hard {} --' . format ( fetch_head_hash ) , error_msg = 'Could not reset Git repo.' ) #NEWLINE# self . _execute_git_command_in_repo_and_raise_on_failure ( git_command = 'clean -dfx' , error_msg = 'Could not clean Git repo.' )