aboutsummaryrefslogtreecommitdiff
path: root/PRESUBMIT.py
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2013-07-24 12:55:54 -0700
committerDerek Schuff <dschuff@chromium.org>2013-07-24 12:55:54 -0700
commit0adde5bbb53bfb2aadcb566c514efd3e218bf0bc (patch)
tree16df45b57f88926fde56cf21d95475b187c362ab /PRESUBMIT.py
parentccad851d1493d84019f3372c0033908cdd516f58 (diff)
Clang: Add presubmit script and OWNERS file to match our LLVM repo
Several people have been bitten recently by the strange git cl behavior that silently fails to push changes if the local branch does not have the correct upstream branch, so copy our llvm presubmit script that checks for this. Also create an OWNERS file, because adding a presubmit script also causes git cl to do an OWNERS check which fails if no OWNERS file is present R=jvoung@chromium.org BUG=none Review URL: https://codereview.chromium.org/20051011
Diffstat (limited to 'PRESUBMIT.py')
-rw-r--r--PRESUBMIT.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
new file mode 100644
index 0000000000..d81168ea09
--- /dev/null
+++ b/PRESUBMIT.py
@@ -0,0 +1,66 @@
+# Copyright (c) 2012 The Native Client Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Documentation on PRESUBMIT.py can be found at:
+# http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
+
+EXCLUDE_PROJECT_CHECKS_DIRS = [ '.' ]
+
+import subprocess
+def CheckGitBranch():
+ p = subprocess.Popen("git branch -vv", shell=True,
+ stdout=subprocess.PIPE)
+ output, _ = p.communicate()
+
+ lines = output.split('\n')
+ for line in lines:
+ # output format for checked-out branch should be
+ # * branchname hash [TrackedBranchName ...
+ toks = line.split()
+ if '*' not in toks[0]:
+ continue
+ if not 'origin/master' in toks[3]:
+ warning = 'Warning: your current branch:\n' + line
+ warning += '\nis not tracking origin/master. git cl push may silently '
+ warning += 'fail to push your change. To fix this, do\n'
+ warning += 'git branch -u origin/master'
+ return warning
+ return None
+ print 'Warning: presubmit check could not determine local git branch'
+ return None
+
+def _CommonChecks(input_api, output_api):
+ """Checks for both upload and commit."""
+ results = []
+ results.extend(input_api.canned_checks.PanProjectChecks(
+ input_api, output_api, project_name='Native Client',
+ excluded_paths=tuple(EXCLUDE_PROJECT_CHECKS_DIRS)))
+ branch_warning = CheckGitBranch()
+ if branch_warning:
+ results.append(output_api.PresubmitPromptWarning(branch_warning))
+ return results
+
+def CheckChangeOnUpload(input_api, output_api):
+ """Verifies all changes in all files.
+ Args:
+ input_api: the limited set of input modules allowed in presubmit.
+ output_api: the limited set of output modules allowed in presubmit.
+ """
+ report = []
+ report.extend(_CommonChecks(input_api, output_api))
+ return report
+
+def CheckChangeOnCommit(input_api, output_api):
+ """Verifies all changes in all files and verifies that the
+ tree is open and can accept a commit.
+ Args:
+ input_api: the limited set of input modules allowed in presubmit.
+ output_api: the limited set of output modules allowed in presubmit.
+ """
+ report = []
+ report.extend(CheckChangeOnUpload(input_api, output_api))
+ return report
+
+def GetPreferredTrySlaves(project, change):
+ return []