OLD | NEW |
1 #!/usr/bin/python | |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 3 # found in the LICENSE file. |
5 | 4 |
6 import os | 5 import os |
7 import re | 6 import re |
8 import subprocess | 7 import subprocess |
9 import sys | 8 import sys |
10 | 9 |
11 # Find depot_tools in PATH, append it to sys.path so we can import. | 10 # Imported from depot_tools. |
12 paths = os.environ.get("PATH") | |
13 for path in paths.split(':'): | |
14 if not path.endswith("depot_tools"): | |
15 continue | |
16 sys.path.append(path) | |
17 break | |
18 | |
19 import gclient_scm | 11 import gclient_scm |
20 import presubmit_support | 12 import presubmit_support |
21 | 13 |
22 def Backquote(cmd, cwd=None): | 14 def Backquote(cmd, cwd=None): |
23 """Like running `cmd` in a shell script.""" | 15 """Like running `cmd` in a shell script.""" |
24 return subprocess.Popen(cmd, | 16 return subprocess.Popen(cmd, |
25 cwd=cwd, | 17 cwd=cwd, |
26 stdout=subprocess.PIPE).communicate()[0].strip() | 18 stdout=subprocess.PIPE).communicate()[0].strip() |
27 | 19 |
28 | 20 |
(...skipping 14 matching lines...) Expand all Loading... |
43 raise Exception("Could not parse log message: %s" % log) | 35 raise Exception("Could not parse log message: %s" % log) |
44 name = m.group(1) | 36 name = m.group(1) |
45 description = m.group(2) | 37 description = m.group(2) |
46 files = gclient_scm.CaptureGitStatus([root], upstream_branch) | 38 files = gclient_scm.CaptureGitStatus([root], upstream_branch) |
47 issue = Backquote(['git', 'cl', 'status', '--field=id']) | 39 issue = Backquote(['git', 'cl', 'status', '--field=id']) |
48 patchset = None | 40 patchset = None |
49 self.change = presubmit_support.GitChange(name, description, root, files, | 41 self.change = presubmit_support.GitChange(name, description, root, files, |
50 issue, patchset) | 42 issue, patchset) |
51 | 43 |
52 | 44 |
53 # Ensure we were called with the necessary number of arguments. | 45 def RunHooks(hook_name, upstream_branch): |
54 program_name = os.path.basename(sys.argv[0]) | 46 commit = (hook_name == 'pre-cl-dcommit') |
55 if len(sys.argv) < 2: | |
56 raise Exception("usage: %s [upstream branch]" % program_name) | |
57 | 47 |
58 # Get arguments from how we were called. | 48 # Create our options based on the command-line args and the current checkout. |
59 commit = (program_name == 'pre-cl-dcommit') | 49 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) |
60 upstream_branch = sys.argv[1] | |
61 | 50 |
62 # Create our options based on the command-line args and the current checkout. | 51 # Run the presubmit checks. |
63 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) | 52 if presubmit_support.DoPresubmitChecks(options.change, |
64 | 53 options.commit, |
65 # Run the presubmit checks. | 54 options.verbose, |
66 if presubmit_support.DoPresubmitChecks(options.change, | 55 sys.stdout, |
67 options.commit, | 56 sys.stdin, |
68 options.verbose, | 57 options.default_presubmit, |
69 sys.stdout, | 58 options.may_prompt): |
70 sys.stdin, | 59 sys.exit(0) |
71 options.default_presubmit, | 60 else: |
72 options.may_prompt): | 61 sys.exit(1) |
73 sys.exit(0) | |
74 else: | |
75 sys.exit(1) | |
OLD | NEW |