Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: git_cl_hooks.py

Issue 399009: Reapply 32057, 32058, 32059, 32062 and fixes problems introduced by these changes. (Closed)
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gclient_utils.py ('k') | presubmit_support.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 # 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
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import re 6 import re
7 import subprocess 7 import subprocess
8 import sys 8 import sys
9 9
10 # Imported from depot_tools.
11 import gclient_scm
12 import presubmit_support 10 import presubmit_support
11 import scm
13 12
14 def Backquote(cmd, cwd=None): 13 def Backquote(cmd, cwd=None):
15 """Like running `cmd` in a shell script.""" 14 """Like running `cmd` in a shell script."""
16 return subprocess.Popen(cmd, 15 return subprocess.Popen(cmd,
17 cwd=cwd, 16 cwd=cwd,
18 stdout=subprocess.PIPE).communicate()[0].strip() 17 stdout=subprocess.PIPE).communicate()[0].strip()
19 18
20 19
21 class ChangeOptions: 20 class ChangeOptions:
22 def __init__(self, commit=None, upstream_branch=None): 21 def __init__(self, commit=None, upstream_branch=None):
23 self.commit = commit 22 self.commit = commit
24 self.verbose = None 23 self.verbose = None
25 self.default_presubmit = None 24 self.default_presubmit = None
26 self.may_prompt = None 25 self.may_prompt = None
27 26
28 root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup'])) 27 root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup']))
29 if not root: 28 if not root:
30 raise Exception("Could not get root directory.") 29 raise Exception("Could not get root directory.")
31 log = Backquote(['git', 'show', '--name-only', 30 log = Backquote(['git', 'show', '--name-only',
32 '--pretty=format:%H%n%s%n%n%b']) 31 '--pretty=format:%H%n%s%n%n%b'])
33 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL) 32 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL)
34 if not m: 33 if not m:
35 raise Exception("Could not parse log message: %s" % log) 34 raise Exception("Could not parse log message: %s" % log)
36 name = m.group(1) 35 name = m.group(1)
37 description = m.group(2) 36 description = m.group(2)
38 files = gclient_scm.CaptureGitStatus([root], upstream_branch) 37 files = scm.GIT.CaptureStatus([root], upstream_branch)
39 issue = Backquote(['git', 'cl', 'status', '--field=id']) 38 issue = Backquote(['git', 'cl', 'status', '--field=id'])
40 patchset = None 39 patchset = None
41 self.change = presubmit_support.GitChange(name, description, root, files, 40 self.change = presubmit_support.GitChange(name, description, root, files,
42 issue, patchset) 41 issue, patchset)
43 42
44 43
45 def RunHooks(hook_name, upstream_branch): 44 def RunHooks(hook_name, upstream_branch):
46 commit = (hook_name == 'pre-cl-dcommit') 45 commit = (hook_name == 'pre-cl-dcommit')
47 46
48 # Create our options based on the command-line args and the current checkout. 47 # Create our options based on the command-line args and the current checkout.
49 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) 48 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch)
50 49
51 # Run the presubmit checks. 50 # Run the presubmit checks.
52 if presubmit_support.DoPresubmitChecks(options.change, 51 if presubmit_support.DoPresubmitChecks(options.change,
53 options.commit, 52 options.commit,
54 options.verbose, 53 options.verbose,
55 sys.stdout, 54 sys.stdout,
56 sys.stdin, 55 sys.stdin,
57 options.default_presubmit, 56 options.default_presubmit,
58 options.may_prompt): 57 options.may_prompt):
59 sys.exit(0) 58 sys.exit(0)
60 else: 59 else:
61 sys.exit(1) 60 sys.exit(1)
OLDNEW
« no previous file with comments | « gclient_utils.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698