| OLD | NEW |
| 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 __future__ import print_function | 10 from __future__ import print_function |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 763 |
| 764 def GetIsGerrit(self): | 764 def GetIsGerrit(self): |
| 765 """Return true if this repo is assosiated with gerrit code review system.""" | 765 """Return true if this repo is assosiated with gerrit code review system.""" |
| 766 if self.is_gerrit is None: | 766 if self.is_gerrit is None: |
| 767 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) | 767 self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) |
| 768 return self.is_gerrit | 768 return self.is_gerrit |
| 769 | 769 |
| 770 def GetSquashGerritUploads(self): | 770 def GetSquashGerritUploads(self): |
| 771 """Return true if uploads to Gerrit should be squashed by default.""" | 771 """Return true if uploads to Gerrit should be squashed by default.""" |
| 772 if self.squash_gerrit_uploads is None: | 772 if self.squash_gerrit_uploads is None: |
| 773 self.squash_gerrit_uploads = ( | 773 self.squash_gerrit_uploads = self.GetSquashGerritUploadsOverride() |
| 774 RunGit(['config', '--bool', 'gerrit.squash-uploads'], | 774 if self.squash_gerrit_uploads is None: |
| 775 error_ok=True).strip() == 'true') | 775 # TODO(tandrii): switch this from ==true to not ==false. |
| 776 self.squash_gerrit_uploads = ( |
| 777 RunGit(['config', '--bool', 'gerrit.squash-uploads'], |
| 778 error_ok=True).strip() == 'true') |
| 776 return self.squash_gerrit_uploads | 779 return self.squash_gerrit_uploads |
| 777 | 780 |
| 781 def GetSquashGerritUploadsOverride(self): |
| 782 """Return True or False if codereview.settings should be overridden. |
| 783 |
| 784 Returns None if no override has been defined. |
| 785 """ |
| 786 # See also http://crbug.com/611892#c23 |
| 787 result = RunGit(['config', '--bool', 'gerrit.override-squash-uploads'], |
| 788 error_ok=True).strip() |
| 789 if result == 'true': |
| 790 return True |
| 791 if result == 'false': |
| 792 return False |
| 793 return None |
| 794 |
| 778 def GetGerritSkipEnsureAuthenticated(self): | 795 def GetGerritSkipEnsureAuthenticated(self): |
| 779 """Return True if EnsureAuthenticated should not be done for Gerrit | 796 """Return True if EnsureAuthenticated should not be done for Gerrit |
| 780 uploads.""" | 797 uploads.""" |
| 781 if self.gerrit_skip_ensure_authenticated is None: | 798 if self.gerrit_skip_ensure_authenticated is None: |
| 782 self.gerrit_skip_ensure_authenticated = ( | 799 self.gerrit_skip_ensure_authenticated = ( |
| 783 RunGit(['config', '--bool', 'gerrit.skip-ensure-authenticated'], | 800 RunGit(['config', '--bool', 'gerrit.skip-ensure-authenticated'], |
| 784 error_ok=True).strip() == 'true') | 801 error_ok=True).strip() == 'true') |
| 785 return self.gerrit_skip_ensure_authenticated | 802 return self.gerrit_skip_ensure_authenticated |
| 786 | 803 |
| 787 def GetGitEditor(self): | 804 def GetGitEditor(self): |
| (...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2331 if reply.lower().startswith('y'): | 2348 if reply.lower().startswith('y'): |
| 2332 gclient_utils.rm_file_or_tree(hook) | 2349 gclient_utils.rm_file_or_tree(hook) |
| 2333 print('Gerrit commit-msg hook removed.') | 2350 print('Gerrit commit-msg hook removed.') |
| 2334 else: | 2351 else: |
| 2335 print('OK, will keep Gerrit commit-msg hook in place.') | 2352 print('OK, will keep Gerrit commit-msg hook in place.') |
| 2336 | 2353 |
| 2337 def CMDUploadChange(self, options, args, change): | 2354 def CMDUploadChange(self, options, args, change): |
| 2338 """Upload the current branch to Gerrit.""" | 2355 """Upload the current branch to Gerrit.""" |
| 2339 if options.squash and options.no_squash: | 2356 if options.squash and options.no_squash: |
| 2340 DieWithError('Can only use one of --squash or --no-squash') | 2357 DieWithError('Can only use one of --squash or --no-squash') |
| 2341 options.squash = ((settings.GetSquashGerritUploads() or options.squash) and | 2358 |
| 2342 not options.no_squash) | 2359 if not options.squash and not options.no_squash: |
| 2360 options.squash = settings.GetSquashGerritUploads() |
| 2361 # TODO(tandrii): remove this by June 20. |
| 2362 if (settings.GetSquashGerritUploadsOverride() is None and |
| 2363 not options.squash): |
| 2364 print('\n\nYou are using git cl upload in --no-squash mode ' |
| 2365 'by default.\n' |
| 2366 'Chrome infrastructure wants to make --squash the default.\n' |
| 2367 'To ensure that --no-squash is still the default for YOU do:\n' |
| 2368 ' git config --bool gerrit.override-squash-uploads false\n' |
| 2369 'See https://goo.gl/dnK2gV (use chromium.org account!) and ' |
| 2370 'let us know what you think. Thanks!\n' |
| 2371 'BUG: http://crbug.com/611892\n\n') |
| 2372 elif options.no_squash: |
| 2373 options.squash = False |
| 2343 | 2374 |
| 2344 # We assume the remote called "origin" is the one we want. | 2375 # We assume the remote called "origin" is the one we want. |
| 2345 # It is probably not worthwhile to support different workflows. | 2376 # It is probably not worthwhile to support different workflows. |
| 2346 gerrit_remote = 'origin' | 2377 gerrit_remote = 'origin' |
| 2347 | 2378 |
| 2348 remote, remote_branch = self.GetRemoteBranch() | 2379 remote, remote_branch = self.GetRemoteBranch() |
| 2349 branch = GetTargetRef(remote, remote_branch, options.target_branch, | 2380 branch = GetTargetRef(remote, remote_branch, options.target_branch, |
| 2350 pending_prefix='') | 2381 pending_prefix='') |
| 2351 | 2382 |
| 2352 if options.squash: | 2383 if options.squash: |
| (...skipping 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5020 if __name__ == '__main__': | 5051 if __name__ == '__main__': |
| 5021 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5052 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 5022 # unit testing. | 5053 # unit testing. |
| 5023 fix_encoding.fix_encoding() | 5054 fix_encoding.fix_encoding() |
| 5024 setup_color.init() | 5055 setup_color.init() |
| 5025 try: | 5056 try: |
| 5026 sys.exit(main(sys.argv[1:])) | 5057 sys.exit(main(sys.argv[1:])) |
| 5027 except KeyboardInterrupt: | 5058 except KeyboardInterrupt: |
| 5028 sys.stderr.write('interrupted\n') | 5059 sys.stderr.write('interrupted\n') |
| 5029 sys.exit(1) | 5060 sys.exit(1) |
| OLD | NEW |