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

Side by Side Diff: git_cl_hooks.py

Issue 391075: Revert 32057, 32058, 32059, 32062 because they still have unwanted side-effects. (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
10 import presubmit_support 12 import presubmit_support
11 import scm
12 13
13 def Backquote(cmd, cwd=None): 14 def Backquote(cmd, cwd=None):
14 """Like running `cmd` in a shell script.""" 15 """Like running `cmd` in a shell script."""
15 return subprocess.Popen(cmd, 16 return subprocess.Popen(cmd,
16 cwd=cwd, 17 cwd=cwd,
17 stdout=subprocess.PIPE).communicate()[0].strip() 18 stdout=subprocess.PIPE).communicate()[0].strip()
18 19
19 20
20 class ChangeOptions: 21 class ChangeOptions:
21 def __init__(self, commit=None, upstream_branch=None): 22 def __init__(self, commit=None, upstream_branch=None):
22 self.commit = commit 23 self.commit = commit
23 self.verbose = None 24 self.verbose = None
24 self.default_presubmit = None 25 self.default_presubmit = None
25 self.may_prompt = None 26 self.may_prompt = None
26 27
27 root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup'])) 28 root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup']))
28 if not root: 29 if not root:
29 raise Exception("Could not get root directory.") 30 raise Exception("Could not get root directory.")
30 log = Backquote(['git', 'show', '--name-only', 31 log = Backquote(['git', 'show', '--name-only',
31 '--pretty=format:%H%n%s%n%n%b']) 32 '--pretty=format:%H%n%s%n%n%b'])
32 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL) 33 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL)
33 if not m: 34 if not m:
34 raise Exception("Could not parse log message: %s" % log) 35 raise Exception("Could not parse log message: %s" % log)
35 name = m.group(1) 36 name = m.group(1)
36 description = m.group(2) 37 description = m.group(2)
37 files = scm.GIT.CaptureStatus([root], upstream_branch) 38 files = gclient_scm.CaptureGitStatus([root], upstream_branch)
38 issue = Backquote(['git', 'cl', 'status', '--field=id']) 39 issue = Backquote(['git', 'cl', 'status', '--field=id'])
39 patchset = None 40 patchset = None
40 self.change = presubmit_support.GitChange(name, description, root, files, 41 self.change = presubmit_support.GitChange(name, description, root, files,
41 issue, patchset) 42 issue, patchset)
42 43
43 44
44 def RunHooks(hook_name, upstream_branch): 45 def RunHooks(hook_name, upstream_branch):
45 commit = (hook_name == 'pre-cl-dcommit') 46 commit = (hook_name == 'pre-cl-dcommit')
46 47
47 # Create our options based on the command-line args and the current checkout. 48 # Create our options based on the command-line args and the current checkout.
48 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) 49 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch)
49 50
50 # Run the presubmit checks. 51 # Run the presubmit checks.
51 if presubmit_support.DoPresubmitChecks(options.change, 52 if presubmit_support.DoPresubmitChecks(options.change,
52 options.commit, 53 options.commit,
53 options.verbose, 54 options.verbose,
54 sys.stdout, 55 sys.stdout,
55 sys.stdin, 56 sys.stdin,
56 options.default_presubmit, 57 options.default_presubmit,
57 options.may_prompt): 58 options.may_prompt):
58 sys.exit(0) 59 sys.exit(0)
59 else: 60 else:
60 sys.exit(1) 61 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