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

Side by Side Diff: git_cl_hooks.py

Issue 438012: Call git diff --name-status with a relative path.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/gclient_scm_test.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 import presubmit_support 10 import presubmit_support
11 import scm 11 import scm
12 12
13 def Backquote(cmd, cwd=None): 13 def Backquote(cmd, cwd=None):
14 """Like running `cmd` in a shell script.""" 14 """Like running `cmd` in a shell script."""
15 return subprocess.Popen(cmd, 15 return subprocess.Popen(cmd,
16 cwd=cwd, 16 cwd=cwd,
17 stdout=subprocess.PIPE).communicate()[0].strip() 17 stdout=subprocess.PIPE).communicate()[0].strip()
18 18
19 19
20 class ChangeOptions: 20 class ChangeOptions:
21 def __init__(self, commit=None, upstream_branch=None): 21 def __init__(self, commit=None, upstream_branch=None):
22 self.commit = commit 22 self.commit = commit
23 self.verbose = None 23 self.verbose = None
24 self.default_presubmit = None 24 self.default_presubmit = None
25 self.may_prompt = None 25 self.may_prompt = None
26 26
27 root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup'])) 27 root = Backquote(['git', 'rev-parse', '--show-cdup'])
28 if not root:
29 root = "."
30 absroot = os.path.abspath(root)
28 if not root: 31 if not root:
29 raise Exception("Could not get root directory.") 32 raise Exception("Could not get root directory.")
30 log = Backquote(['git', 'show', '--name-only', 33 log = Backquote(['git', 'show', '--name-only',
31 '--pretty=format:%H%n%s%n%n%b']) 34 '--pretty=format:%H%n%s%n%n%b'])
32 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL) 35 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL)
33 if not m: 36 if not m:
34 raise Exception("Could not parse log message: %s" % log) 37 raise Exception("Could not parse log message: %s" % log)
35 name = m.group(1) 38 name = m.group(1)
36 description = m.group(2) 39 description = m.group(2)
37 files = scm.GIT.CaptureStatus([root], upstream_branch) 40 files = scm.GIT.CaptureStatus([root], upstream_branch)
38 issue = Backquote(['git', 'cl', 'status', '--field=id']) 41 issue = Backquote(['git', 'cl', 'status', '--field=id'])
39 patchset = None 42 patchset = None
40 self.change = presubmit_support.GitChange(name, description, root, files, 43 self.change = presubmit_support.GitChange(name, description, absroot, files,
41 issue, patchset) 44 issue, patchset)
42 45
43 46
44 def RunHooks(hook_name, upstream_branch): 47 def RunHooks(hook_name, upstream_branch):
45 commit = (hook_name == 'pre-cl-dcommit') 48 commit = (hook_name == 'pre-cl-dcommit')
46 49
47 # Create our options based on the command-line args and the current checkout. 50 # Create our options based on the command-line args and the current checkout.
48 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) 51 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch)
49 52
50 # Run the presubmit checks. 53 # Run the presubmit checks.
51 if presubmit_support.DoPresubmitChecks(options.change, 54 if presubmit_support.DoPresubmitChecks(options.change,
52 options.commit, 55 options.commit,
53 options.verbose, 56 options.verbose,
54 sys.stdout, 57 sys.stdout,
55 sys.stdin, 58 sys.stdin,
56 options.default_presubmit, 59 options.default_presubmit,
57 options.may_prompt): 60 options.may_prompt):
58 sys.exit(0) 61 sys.exit(0)
59 else: 62 else:
60 sys.exit(1) 63 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698