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