You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
814 B

  1. """Ensure text files have the proper line endings.
  2. """
  3. from subprocess import CalledProcessError
  4. from milc import cli
  5. @cli.subcommand("Ensure text files have the proper line endings.", hidden=True)
  6. def format_text(cli):
  7. """Ensure text files have the proper line endings.
  8. """
  9. try:
  10. file_list_cmd = cli.run(['git', 'ls-files', '-z'], check=True)
  11. except CalledProcessError as e:
  12. cli.log.error('Could not get file list: %s', e)
  13. exit(1)
  14. except Exception as e:
  15. cli.log.error('Unhandled exception: %s: %s', e.__class__.__name__, e)
  16. cli.log.exception(e)
  17. exit(1)
  18. dos2unix = cli.run(['xargs', '-0', 'dos2unix'], stdin=None, input=file_list_cmd.stdout)
  19. if dos2unix.returncode != 0:
  20. print(dos2unix.stderr)
  21. return dos2unix.returncode