This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
mirrored from https://chromium.googlesource.com/chromium/dom-distiller
-
Notifications
You must be signed in to change notification settings - Fork 82
/
PRESUBMIT.py
47 lines (38 loc) · 1.63 KB
/
PRESUBMIT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for DOM Distiller.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into git cl.
"""
import subprocess
import sys
def _Git(args):
"""Runs the requested git command and returns the first line of output."""
output = subprocess.check_output(['git'] + args)
return output.split('\n')[0]
def _CheckUpstream(input_api, output_api):
"""Checks that the upstream branch is remote.
git cl push will push the issue's change to the branch's upstream branch. This
should be origin/master (or maybe origin/some_branch) to work as expected.
Otherwise, git cl push will push the change to some local branch and close the
issue.
"""
branch = _Git(['symbolic-ref', 'HEAD'])
shortbranch = branch.replace('refs/heads/', '')
remote = _Git(['config', '--local', 'branch.%s.remote' % shortbranch])
if remote != 'origin':
upstream = _Git(['config', '--local', 'branch.%s.merge' % shortbranch])
shortupstream = upstream.replace('refs/heads/', '')
return [output_api.PresubmitError(
'Changes should be pushed to origin/master.\n'
'Try this:\n'
' git branch -u origin/master\n'
' git cl push\n'
' git branch -u %s' % shortupstream)]
return []
def CheckChangeOnCommit(input_api, output_api):
results = []
results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
results.extend(_CheckUpstream(input_api, output_api))
return results