git-cl: simplify squash commandline parsing
We can have --no-squash update the --squash state directly so we don't
have to constantly check two different knobs. This means opts.squash
is now a tristate: None means load config settings while True/False
means the user has specified a command line option. This also means
we don't have to detect multiple --squash/--no-squash flags as the
argparse module will take care of coalescing.
Bug: 993518
Test: `git cl upload` uses my ~/.gitconfig
Test: `git cl upload --squash` squashes
Test: `git cl upload --no-squash` doesn't squash
Change-Id: Ib2577db11d3af03c93cb47d8b78b341213720a92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1754234
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index a52b0ae..d72410f 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2652,14 +2652,9 @@
def CMDUploadChange(self, options, git_diff_args, custom_cl_base, change):
"""Upload the current branch to Gerrit."""
- if options.squash and options.no_squash:
- DieWithError('Can only use one of --squash or --no-squash')
-
- if not options.squash and not options.no_squash:
+ if options.squash is None:
# Load default for user, repo, squash=true, in this order.
options.squash = settings.GetSquashGerritUploads()
- elif options.no_squash:
- options.squash = False
remote, remote_branch = self.GetRemoteBranch()
branch = GetTargetRef(remote, remote_branch, options.target_branch)
@@ -4740,7 +4735,7 @@
'Default: remote branch head, or master')
parser.add_option('--squash', action='store_true',
help='Squash multiple commits into one')
- parser.add_option('--no-squash', action='store_true',
+ parser.add_option('--no-squash', action='store_false', dest='squash',
help='Don\'t squash multiple commits into one')
parser.add_option('--topic', default=None,
help='Topic to specify when uploading')