OLD | NEW |
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 breakpad | 10 import breakpad |
(...skipping 22 matching lines...) Expand all Loading... |
33 self.verbose = None | 33 self.verbose = None |
34 self.default_presubmit = None | 34 self.default_presubmit = None |
35 self.may_prompt = None | 35 self.may_prompt = None |
36 | 36 |
37 root = Backquote(['git', 'rev-parse', '--show-cdup']) | 37 root = Backquote(['git', 'rev-parse', '--show-cdup']) |
38 if not root: | 38 if not root: |
39 root = "." | 39 root = "." |
40 absroot = os.path.abspath(root) | 40 absroot = os.path.abspath(root) |
41 if not root: | 41 if not root: |
42 raise Exception("Could not get root directory.") | 42 raise Exception("Could not get root directory.") |
43 log = Backquote(['git', 'show', '--name-only', | 43 # We use the sha1 of HEAD as a name of this change. |
44 '--pretty=format:%H%n%s%n%n%b']) | 44 name = Backquote(['git', 'rev-parse', 'HEAD']) |
45 m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL) | |
46 if not m: | |
47 raise Exception("Could not parse log message: %s" % log) | |
48 name = m.group(1) | |
49 files = scm.GIT.CaptureStatus([root], upstream_branch) | 45 files = scm.GIT.CaptureStatus([root], upstream_branch) |
50 issue = BackquoteAsInteger(['git', 'cl', 'status', '--field=id']) | 46 issue = BackquoteAsInteger(['git', 'cl', 'status', '--field=id']) |
51 patchset = BackquoteAsInteger(['git', 'cl', 'status', '--field=patch']) | 47 patchset = BackquoteAsInteger(['git', 'cl', 'status', '--field=patch']) |
52 if issue: | 48 if issue: |
53 description = Backquote(['git', 'cl', 'status', '--field=desc']) | 49 description = Backquote(['git', 'cl', 'status', '--field=desc']) |
54 else: | 50 else: |
55 description = m.group(2) | 51 # If the change was never uploaded, use the log messages of all commits |
| 52 # up to the branch point, as git cl upload will prefill the description |
| 53 # with these log messages. |
| 54 description = Backquote(['git', 'log', '--pretty=format:%s%n%n%b', |
| 55 '%s...' % (upstream_branch)]) |
56 self.change = presubmit_support.GitChange(name, description, absroot, files, | 56 self.change = presubmit_support.GitChange(name, description, absroot, files, |
57 issue, patchset) | 57 issue, patchset) |
58 | 58 |
59 | 59 |
60 def RunHooks(hook_name, upstream_branch): | 60 def RunHooks(hook_name, upstream_branch): |
61 commit = (hook_name == 'pre-cl-dcommit') | 61 commit = (hook_name == 'pre-cl-dcommit') |
62 | 62 |
63 # Create our options based on the command-line args and the current checkout. | 63 # Create our options based on the command-line args and the current checkout. |
64 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) | 64 options = ChangeOptions(commit=commit, upstream_branch=upstream_branch) |
65 | 65 |
66 # Apply watchlists on upload. | 66 # Apply watchlists on upload. |
67 if not commit: | 67 if not commit: |
68 watchlist = watchlists.Watchlists(options.change.RepositoryRoot()) | 68 watchlist = watchlists.Watchlists(options.change.RepositoryRoot()) |
69 files = [f.LocalPath() for f in options.change.AffectedFiles()] | 69 files = [f.LocalPath() for f in options.change.AffectedFiles()] |
70 watchers = watchlist.GetWatchersForPaths(files) | 70 watchers = watchlist.GetWatchersForPaths(files) |
71 Backquote(['git', 'config', '--replace-all', | 71 Backquote(['git', 'config', '--replace-all', |
72 'rietveld.extracc', ','.join(watchers)]) | 72 'rietveld.extracc', ','.join(watchers)]) |
73 | 73 |
74 # Run the presubmit checks. | 74 # Run the presubmit checks. |
75 if presubmit_support.DoPresubmitChecks(options.change, | 75 if presubmit_support.DoPresubmitChecks(options.change, |
76 options.commit, | 76 options.commit, |
77 options.verbose, | 77 options.verbose, |
78 sys.stdout, | 78 sys.stdout, |
79 sys.stdin, | 79 sys.stdin, |
80 options.default_presubmit, | 80 options.default_presubmit, |
81 options.may_prompt): | 81 options.may_prompt): |
82 sys.exit(0) | 82 sys.exit(0) |
83 else: | 83 else: |
84 sys.exit(1) | 84 sys.exit(1) |
OLD | NEW |