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.

28 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  2. #
  3. # Use of this source code is governed by a BSD-style license
  4. # that can be found in the LICENSE file in the root of the source
  5. # tree. An additional intellectual property rights grant can be found
  6. # in the file PATENTS. All contributing project authors may
  7. # be found in the AUTHORS file in the root of the source tree.
  8. def CheckChangeOnUpload(input_api, output_api):
  9. results = []
  10. results.extend(CheckPatchFormatted(input_api, output_api))
  11. return results
  12. def CheckPatchFormatted(input_api, output_api):
  13. import git_cl
  14. cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()]
  15. code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True)
  16. if code == 2:
  17. short_path = input_api.basename(input_api.PresubmitLocalPath())
  18. full_path = input_api.os_path.relpath(input_api.PresubmitLocalPath(),
  19. input_api.change.RepositoryRoot())
  20. return [output_api.PresubmitPromptWarning(
  21. 'The %s directory requires source formatting. '
  22. 'Please run git cl format %s' %
  23. (short_path, full_path))]
  24. # As this is just a warning, ignore all other errors if the user
  25. # happens to have a broken clang-format, doesn't use git, etc etc.
  26. return []