gofmt.py 616 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. import subprocess
  3. from env import commit_range
  4. files = subprocess.check_output([
  5. 'git', 'diff', '--diff-filter=ACMR',
  6. '--name-only', '...'.join(commit_range), '--',
  7. ])
  8. exit_status = 0
  9. for filename in files.split('\n'):
  10. if filename.endswith('.go'):
  11. try:
  12. out = subprocess.check_output(['gofmt', '-s', '-l', filename])
  13. if out != '':
  14. print out,
  15. exit_status = 1
  16. except subprocess.CalledProcessError:
  17. exit_status = 1
  18. if exit_status != 0:
  19. print 'Reformat the files listed above with "gofmt -s -w" and try again.'
  20. exit(exit_status)
  21. print 'All files pass gofmt.'
  22. exit(0)