|
1 # Copyright (C) 2010 Google Inc. All rights reserved. |
|
2 # |
|
3 # Redistribution and use in source and binary forms, with or without |
|
4 # modification, are permitted provided that the following conditions are |
|
5 # met: |
|
6 # |
|
7 # * Redistributions of source code must retain the above copyright |
|
8 # notice, this list of conditions and the following disclaimer. |
|
9 # * Redistributions in binary form must reproduce the above |
|
10 # copyright notice, this list of conditions and the following disclaimer |
|
11 # in the documentation and/or other materials provided with the |
|
12 # distribution. |
|
13 # * Neither the name of Google Inc. nor the names of its |
|
14 # contributors may be used to endorse or promote products derived from |
|
15 # this software without specific prior written permission. |
|
16 # |
|
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
|
29 from webkitpy.common.checkout.scm import AuthenticationError, AmbiguousCommitError |
|
30 from webkitpy.common.system.executive import ScriptError |
|
31 from webkitpy.common.system.user import User |
|
32 from webkitpy.tool.steps.abstractstep import AbstractStep |
|
33 from webkitpy.tool.steps.options import Options |
|
34 |
|
35 |
|
36 class Commit(AbstractStep): |
|
37 @classmethod |
|
38 def options(cls): |
|
39 return AbstractStep.options() + [ |
|
40 Options.git_commit, |
|
41 ] |
|
42 |
|
43 def _commit_warning(self, error): |
|
44 working_directory_message = "" if error.working_directory_is_clean else " and working copy changes" |
|
45 return ('There are %s local commits%s. Everything will be committed as a single commit. ' |
|
46 'To avoid this prompt, set "git config webkit-patch.squash true".' % ( |
|
47 error.num_local_commits, working_directory_message)) |
|
48 |
|
49 def run(self, state): |
|
50 self._commit_message = self._tool.checkout().commit_message_for_this_commit(self._options.git_commit).message() |
|
51 if len(self._commit_message) < 50: |
|
52 raise Exception("Attempted to commit with a commit message shorter than 50 characters. Either your patch is missing a ChangeLog or webkit-patch may have a bug.") |
|
53 |
|
54 self._state = state |
|
55 |
|
56 username = None |
|
57 force_squash = False |
|
58 |
|
59 num_tries = 0 |
|
60 while num_tries < 3: |
|
61 num_tries += 1 |
|
62 |
|
63 try: |
|
64 self._state["commit_text"] = self._tool.scm().commit_with_message(self._commit_message, git_commit=self._options.git_commit, username=username, force_squash=force_squash) |
|
65 break; |
|
66 except AmbiguousCommitError, e: |
|
67 if self._tool.user.confirm(self._commit_warning(e)): |
|
68 force_squash = True |
|
69 else: |
|
70 # This will correctly interrupt the rest of the commit process. |
|
71 raise ScriptError(message="Did not commit") |
|
72 except AuthenticationError, e: |
|
73 username = self._tool.user.prompt("%s login: " % e.server_host, repeat=5) |
|
74 if not username: |
|
75 raise ScriptError("You need to specify the username on %s to perform the commit as." % self.svn_server_host) |