From 54b400c89ff86c5a990b89296f82cfa15dadf238 Mon Sep 17 00:00:00 2001 From: "bauerb@chromium.org" Date: Thu, 14 Jan 2016 10:08:25 +0000 Subject: [PATCH] Add a setting to squash Gerrit uploads by default, and a --no-squash command line option to override it. BUG=nope Review URL: https://codereview.chromium.org/1584703005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298260 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 22 ++++++++++++++++++++++ tests/git_cl_test.py | 1 + 2 files changed, 23 insertions(+) diff --git a/git_cl.py b/git_cl.py index e99509f19..b5289f772 100755 --- a/git_cl.py +++ b/git_cl.py @@ -434,6 +434,7 @@ class Settings(object): self.viewvc_url = None self.updated = False self.is_gerrit = None + self.squash_gerrit_uploads = None self.git_editor = None self.project = None self.force_https_commit_url = None @@ -599,6 +600,14 @@ class Settings(object): self.is_gerrit = self._GetConfig('gerrit.host', error_ok=True) return self.is_gerrit + def GetSquashGerritUploads(self): + """Return true if uploads to Gerrit should be squashed by default.""" + if self.squash_gerrit_uploads is None: + self.squash_gerrit_uploads = ( + RunGit(['config', '--bool', 'gerrit.squash-uploads'], + error_ok=True).strip() == 'true') + return self.squash_gerrit_uploads + def GetGitEditor(self): """Return the editor specified in the git config, or None if none is.""" if self.git_editor is None: @@ -1387,6 +1396,10 @@ def LoadCodereviewSettingsFromFile(fileobj): if 'GERRIT_HOST' in keyvals: RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) + if 'GERRIT_SQUASH_UPLOADS' in keyvals: + RunGit(['config', 'gerrit.squash-uploads', + keyvals['GERRIT_SQUASH_UPLOADS']]) + if 'PUSH_URL_CONFIG' in keyvals and 'ORIGIN_URL_CONFIG' in keyvals: #should be of the form #PUSH_URL_CONFIG: url.ssh://gitrw.chromium.org.pushinsteadof @@ -2354,6 +2367,9 @@ def CMDupload(parser, args): 'Default: remote branch head, or master') parser.add_option('--squash', action='store_true', help='Squash multiple commits into one (Gerrit only)') + parser.add_option('--no-squash', action='store_true', + help='Don\'t squash multiple commits into one ' + + '(Gerrit only)') parser.add_option('--email', default=None, help='email address to use to connect to Rietveld') parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true', @@ -2437,6 +2453,12 @@ def CMDupload(parser, args): print_stats(options.similarity, options.find_copies, args) if settings.GetIsGerrit(): + if options.squash and options.no_squash: + DieWithError('Can only use one of --squash or --no-squash') + + options.squash = ((settings.GetSquashGerritUploads() or options.squash) and + not options.no_squash) + return GerritUpload(options, args, cl, change) ret = RietveldUpload(options, args, cl, change) if not ret: diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 220e59164..b5e14dcc8 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -585,6 +585,7 @@ class TestGitCl(TestCase): def _gerrit_upload_calls(description, reviewers, squash, expected_upstream_ref='origin/refs/heads/master'): calls = [ + ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],), description)