OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 # Documentation on PRESUBMIT.py can be found at: |
| 6 # http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 7 |
| 8 EXCLUDE_PROJECT_CHECKS_DIRS = [ '.' ] |
| 9 |
| 10 import subprocess |
| 11 def CheckGitBranch(): |
| 12 p = subprocess.Popen("git branch -vv", shell=True, |
| 13 stdout=subprocess.PIPE) |
| 14 output, _ = p.communicate() |
| 15 |
| 16 lines = output.split('\n') |
| 17 for line in lines: |
| 18 # output format for checked-out branch should be |
| 19 # * branchname hash [TrackedBranchName ... |
| 20 toks = line.split() |
| 21 if '*' not in toks[0]: |
| 22 continue |
| 23 if not 'origin/master' in toks[3]: |
| 24 warning = 'Warning: your current branch:\n' + line |
| 25 warning += '\nis not tracking origin/master. git cl push may silently ' |
| 26 warning += 'fail to push your change. To fix this, do\n' |
| 27 warning += 'git branch -u origin/master' |
| 28 return warning |
| 29 return None |
| 30 print 'Warning: presubmit check could not determine local git branch' |
| 31 return None |
| 32 |
| 33 def _CommonChecks(input_api, output_api): |
| 34 """Checks for both upload and commit.""" |
| 35 results = [] |
| 36 results.extend(input_api.canned_checks.PanProjectChecks( |
| 37 input_api, output_api, project_name='Native Client', |
| 38 excluded_paths=tuple(EXCLUDE_PROJECT_CHECKS_DIRS))) |
| 39 branch_warning = CheckGitBranch() |
| 40 if branch_warning: |
| 41 results.append(output_api.PresubmitPromptWarning(branch_warning)) |
| 42 return results |
| 43 |
| 44 def CheckChangeOnUpload(input_api, output_api): |
| 45 """Verifies all changes in all files. |
| 46 Args: |
| 47 input_api: the limited set of input modules allowed in presubmit. |
| 48 output_api: the limited set of output modules allowed in presubmit. |
| 49 """ |
| 50 report = [] |
| 51 report.extend(_CommonChecks(input_api, output_api)) |
| 52 return report |
| 53 |
| 54 def CheckChangeOnCommit(input_api, output_api): |
| 55 """Verifies all changes in all files and verifies that the |
| 56 tree is open and can accept a commit. |
| 57 Args: |
| 58 input_api: the limited set of input modules allowed in presubmit. |
| 59 output_api: the limited set of output modules allowed in presubmit. |
| 60 """ |
| 61 report = [] |
| 62 report.extend(CheckChangeOnUpload(input_api, output_api)) |
| 63 return report |
| 64 |
| 65 def GetPreferredTrySlaves(project, change): |
| 66 return [] |
OLD | NEW |