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

Side by Side Diff: git_cl.py

Issue 2045973002: Gerrit git cl upload: warn and offer to remove Gerrit commit-msg hook. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: review Created 4 years, 6 months 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
« no previous file with comments | « no previous file | tests/git_cl_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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld and Gerrit.""" 8 """A git-command for integrating reviews on Rietveld and Gerrit."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 else: 2307 else:
2308 part = parsed_url.path 2308 part = parsed_url.path
2309 match = re.match('(/c)?/(\d+)(/(\d+)?/?)?$', part) 2309 match = re.match('(/c)?/(\d+)(/(\d+)?/?)?$', part)
2310 if match: 2310 if match:
2311 return _ParsedIssueNumberArgument( 2311 return _ParsedIssueNumberArgument(
2312 issue=int(match.group(2)), 2312 issue=int(match.group(2)),
2313 patchset=int(match.group(4)) if match.group(4) else None, 2313 patchset=int(match.group(4)) if match.group(4) else None,
2314 hostname=parsed_url.netloc) 2314 hostname=parsed_url.netloc)
2315 return None 2315 return None
2316 2316
2317 def _GerritCommitMsgHookCheck(self, offer_removal):
2318 hook = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg')
2319 if not os.path.exists(hook):
2320 return
2321 # Crude attempt to distinguish Gerrit Codereview hook from potentially
2322 # custom developer made one.
2323 data = gclient_utils.FileRead(hook)
2324 if not('From Gerrit Code Review' in data and 'add_ChangeId()' in data):
2325 return
2326 print('Warning: you have Gerrit commit-msg hook installed.\n'
2327 'It is not neccessary for uploading with git cl in squash mode, '
2328 'and may interfere with it in subtle ways.\n'
2329 'We recommend you remove the commit-msg hook.')
2330 if offer_removal:
2331 reply = ask_for_data('Do you want to remove it now? [Yes/No]')
2332 if reply.lower().startswith('y'):
2333 gclient_utils.rm_file_or_tree(hook)
2334 print('Gerrit commit-msg hook removed.')
2335 else:
2336 print('OK, will keep Gerrit commit-msg hook in place.')
2337
2317 def CMDUploadChange(self, options, args, change): 2338 def CMDUploadChange(self, options, args, change):
2318 """Upload the current branch to Gerrit.""" 2339 """Upload the current branch to Gerrit."""
2319 if options.squash and options.no_squash: 2340 if options.squash and options.no_squash:
2320 DieWithError('Can only use one of --squash or --no-squash') 2341 DieWithError('Can only use one of --squash or --no-squash')
2321 options.squash = ((settings.GetSquashGerritUploads() or options.squash) and 2342 options.squash = ((settings.GetSquashGerritUploads() or options.squash) and
2322 not options.no_squash) 2343 not options.no_squash)
2323 # We assume the remote called "origin" is the one we want. 2344 # We assume the remote called "origin" is the one we want.
2324 # It is probably not worthwhile to support different workflows. 2345 # It is probably not worthwhile to support different workflows.
2325 gerrit_remote = 'origin' 2346 gerrit_remote = 'origin'
2326 2347
2327 remote, remote_branch = self.GetRemoteBranch() 2348 remote, remote_branch = self.GetRemoteBranch()
2328 branch = GetTargetRef(remote, remote_branch, options.target_branch, 2349 branch = GetTargetRef(remote, remote_branch, options.target_branch,
2329 pending_prefix='') 2350 pending_prefix='')
2330 2351
2331 if options.squash: 2352 if options.squash:
2353 self._GerritCommitMsgHookCheck(offer_removal=not options.force)
2332 if not self.GetIssue(): 2354 if not self.GetIssue():
2333 # TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility 2355 # TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility
2334 # with shadow branch, which used to contain change-id for a given 2356 # with shadow branch, which used to contain change-id for a given
2335 # branch, using which we can fetch actual issue number and set it as the 2357 # branch, using which we can fetch actual issue number and set it as the
2336 # property of the branch, which is the new way. 2358 # property of the branch, which is the new way.
2337 message = RunGitSilent([ 2359 message = RunGitSilent([
2338 'show', '--format=%B', '-s', 2360 'show', '--format=%B', '-s',
2339 'refs/heads/git_cl_uploads/%s' % self.GetBranch()]) 2361 'refs/heads/git_cl_uploads/%s' % self.GetBranch()])
2340 if message: 2362 if message:
2341 change_ids = git_footers.get_footer_change_id(message.strip()) 2363 change_ids = git_footers.get_footer_change_id(message.strip())
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after
4935 if __name__ == '__main__': 4957 if __name__ == '__main__':
4936 # These affect sys.stdout so do it outside of main() to simplify mocks in 4958 # These affect sys.stdout so do it outside of main() to simplify mocks in
4937 # unit testing. 4959 # unit testing.
4938 fix_encoding.fix_encoding() 4960 fix_encoding.fix_encoding()
4939 setup_color.init() 4961 setup_color.init()
4940 try: 4962 try:
4941 sys.exit(main(sys.argv[1:])) 4963 sys.exit(main(sys.argv[1:]))
4942 except KeyboardInterrupt: 4964 except KeyboardInterrupt:
4943 sys.stderr.write('interrupted\n') 4965 sys.stderr.write('interrupted\n')
4944 sys.exit(1) 4966 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698