blob: 876a86051015109b88541c3dc45ec94bf1458c65 [file] [log] [blame]
magjed60601862016-09-29 05:35:54 -07001# 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
Mirko Bonadei8cc66952020-10-30 10:13:45 +01009
magjed60601862016-09-29 05:35:54 -070010def CheckChangeOnUpload(input_api, output_api):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010011 results = []
12 results.extend(CheckPatchFormatted(input_api, output_api))
13 return results
14
magjed60601862016-09-29 05:35:54 -070015
16def CheckPatchFormatted(input_api, output_api):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010017 import git_cl
18 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()]
19 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True)
20 if code == 2:
21 short_path = input_api.basename(input_api.PresubmitLocalPath())
22 full_path = input_api.os_path.relpath(
23 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot())
24 return [
25 output_api.PresubmitPromptWarning(
26 'The %s directory requires source formatting. '
27 'Please run git cl format %s' % (short_path, full_path))
28 ]
29 # As this is just a warning, ignore all other errors if the user
30 # happens to have a broken clang-format, doesn't use git, etc etc.
31 return []