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 def _commit_warning(self, error): 40 working_directory_message = "" if error.working_directory_is_clean else " and working copy changes" 41 return ('There are %s local commits%s. Everything will be committed as a single commit. ' 42 'To avoid this prompt, set "git config webkit-patch.commit-should-always-squash true".' % ( 43 error.num_local_commits, working_directory_message)) 44 45 def run(self, state): 46 self._commit_message = self._tool.checkout().commit_message_for_this_commit(self._options.git_commit).message() 47 if len(self._commit_message) < 50: 48 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.") 49 50 self._state = state 51 52 username = None 53 password = None 54 force_squash = False 55 56 num_tries = 0 57 while num_tries < 3: 58 num_tries += 1 59 60 try: 61 scm = self._tool.scm() 62 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)) 63 svn_revision = scm.svn_revision_from_commit_text(commit_text) 64 log("Committed r%s: <%s>" % (svn_revision, urls.view_revision_url(svn_revision))) 65 self._state["commit_text"] = commit_text 66 break; 67 except AmbiguousCommitError, e: 68 if self._tool.user.confirm(self._commit_warning(e)): 69 force_squash = True 70 else: 71 # This will correctly interrupt the rest of the commit process. 72 raise ScriptError(message="Did not commit") 73 except AuthenticationError, e: 74 username = self._tool.user.prompt("%s login: " % e.server_host, repeat=5) 75 if not username: 76 raise ScriptError("You need to specify the username on %s to perform the commit as." % e.server_host) 77 if e.prompt_for_password: 78 password = self._tool.user.prompt_password("%s password for %s: " % (e.server_host, username), repeat=5) 79 if not password: 80 raise ScriptError("You need to specify the password for %s on %s to perform the commit." % (username, e.server_host)) 81