original_docstring: Installs the pre_push_hook script and makes it executable.
      It ensures that oppia/ is the root folder.
  
      Raises:
          ValueError. Raise ValueError if chmod command fails.
      
docstring: Installs the pre_push_hook script and makes it executable.
  It ensures that oppia/ is the root folder.
  
  
docstring_tokens: Installs the pre_push_hook script and makes it executable . It ensures that oppia / is the root folder .
code: def install_hook():
      """Installs the pre_push_hook script and makes it executable.
      It ensures that oppia/ is the root folder.
  
      Raises:
          ValueError. Raise ValueError if chmod command fails.
      """
      oppia_dir = os.getcwd()
      hooks_dir = os.path.join(oppia_dir, '.git', 'hooks')
      pre_push_file = os.path.join(hooks_dir, 'pre-push')
      chmod_cmd = ['chmod', '+x', pre_push_file]
      file_is_symlink = os.path.islink(pre_push_file)
      file_exists = os.path.exists(pre_push_file)
      if file_is_symlink and file_exists:
          print('Symlink already exists')
      else:
          # If its a broken symlink, delete it.
          if file_is_symlink and not file_exists:
              os.unlink(pre_push_file)
              print('Removing broken symlink')
          try:
              os.symlink(os.path.abspath(__file__), pre_push_file)
              print('Created symlink in .git/hooks directory')
          # Raises AttributeError on windows, OSError added as failsafe.
          except (OSError, AttributeError):
              shutil.copy(__file__, pre_push_file)
              print('Copied file to .git/hooks directory')
  
      print('Making pre-push hook file executable ...')
      _, err_chmod_cmd = start_subprocess_for_result(chmod_cmd)
  
      if not err_chmod_cmd:
          print('pre-push hook file is now executable!')
      else:
          raise ValueError(err_chmod_cmd)
code_tokens: def install_hook ( ) : oppia_dir = os . getcwd ( ) hooks_dir = os . path . join ( oppia_dir , '.git' , 'hooks' ) pre_push_file = os . path . join ( hooks_dir , 'pre-push' ) chmod_cmd = [ 'chmod' , '+x' , pre_push_file ] file_is_symlink = os . path . islink ( pre_push_file ) file_exists = os . path . exists ( pre_push_file ) if file_is_symlink and file_exists : print ( 'Symlink already exists' ) else : if file_is_symlink and not file_exists : os . unlink ( pre_push_file ) print ( 'Removing broken symlink' ) try : os . symlink ( os . path . abspath ( __file__ ) , pre_push_file ) print ( 'Created symlink in .git/hooks directory' ) except ( OSError , AttributeError ) : shutil . copy ( __file__ , pre_push_file ) print ( 'Copied file to .git/hooks directory' ) print ( 'Making pre-push hook file executable ...' ) _ , err_chmod_cmd = start_subprocess_for_result ( chmod_cmd ) if not err_chmod_cmd : print ( 'pre-push hook file is now executable!' ) else : raise ValueError ( err_chmod_cmd )
short_docstring: Installs the pre_push_hook script and makes it executable.
short_docstring_tokens: Installs the pre_push_hook script and makes it executable .
comment: """Installs the pre_push_hook script and makes it executable.
      It ensures that oppia/ is the root folder.
  
      Raises:
          ValueError. Raise ValueError if chmod command fails.
      """$SEP$# If its a broken symlink, delete it.$SEP$# Raises AttributeError on windows, OSError added as failsafe.