initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / tool / steps / commit.py
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.config import urls
31 from webkitpy.common.system.deprecated_logging import log
32 from webkitpy.common.system.executive import ScriptError
33 from webkitpy.common.system.user import User
34 from webkitpy.tool.steps.abstractstep import AbstractStep
35 from webkitpy.tool.steps.options import Options
36
37
38 class Commit(AbstractStep):
39     # FIXME: This option exists only to make sure we don't break scripts which include --ignore-builders
40     # You can safely delete this option any time after 11/01/11.
41     @classmethod
42     def options(cls):
43         return AbstractStep.options() + [
44             Options.check_builders,
45         ]
46
47     def _commit_warning(self, error):
48         working_directory_message = "" if error.working_directory_is_clean else " and working copy changes"
49         return ('There are %s local commits%s. Everything will be committed as a single commit. '
50                 'To avoid this prompt, set "git config webkit-patch.commit-should-always-squash true".' % (
51                 error.num_local_commits, working_directory_message))
52
53     def run(self, state):
54         self._commit_message = self._tool.checkout().commit_message_for_this_commit(self._options.git_commit).message()
55         if len(self._commit_message) < 10:
56             raise Exception("Attempted to commit with a commit message shorter than 10 characters.  Either your patch is missing a ChangeLog or webkit-patch may have a bug.")
57
58         self._state = state
59
60         username = None
61         password = None
62         force_squash = False
63
64         num_tries = 0
65         while num_tries < 3:
66             num_tries += 1
67
68             try:
69                 scm = self._tool.scm()
70                 commit_text = scm.commit_with_message(self._commit_message, git_commit=self._options.git_commit, username=username, password=password, force_squash=force_squash, changed_files=self._changed_files(state))
71                 svn_revision = scm.svn_revision_from_commit_text(commit_text)
72                 log("Committed r%s: <%s>" % (svn_revision, urls.view_revision_url(svn_revision)))
73                 self._state["commit_text"] = commit_text
74                 break;
75             except AmbiguousCommitError, e:
76                 if self._tool.user.confirm(self._commit_warning(e)):
77                     force_squash = True
78                 else:
79                     # This will correctly interrupt the rest of the commit process.
80                     raise ScriptError(message="Did not commit")
81             except AuthenticationError, e:
82                 username = self._tool.user.prompt("%s login: " % e.server_host, repeat=5)
83                 if not username:
84                     raise ScriptError("You need to specify the username on %s to perform the commit as." % e.server_host)
85                 if e.prompt_for_password:
86                     password = self._tool.user.prompt_password("%s password for %s: " % (e.server_host, username), repeat=5)
87                     if not password:
88                         raise ScriptError("You need to specify the password for %s on %s to perform the commit." % (username, e.server_host))