Fix the --no-python flag for git cl format.

The current behavior of the --no-python flag doesn't disable formatting
for python files. Instead, it has the same effect as the --python flag.

Change-Id: I26024d3030b9c873180b488d00351676c37c9492
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1985785
Commit-Queue: Garrett Beaty <gbeaty@chromium.org>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
changes/85/1985785/7
Garrett Beaty 5 years ago committed by Commit Bot
parent ecc27074d2
commit 91a6f33848

@ -5140,12 +5140,11 @@ def CMDformat(parser, args):
parser.add_option(
'--no-python',
action='store_true',
dest='python',
default=False,
help='Disables python formatting on all python files. '
'Takes precedence over --python. '
'If neither --python or --no-python are set, python '
'files that have a .style.yapf file in an ancestor '
'directory will be formatted.')
'If neither --python or --no-python are set, python files that have a '
'.style.yapf file in an ancestor directory will be formatted. '
'It is an error to set both.')
parser.add_option('--js', action='store_true',
help='Format javascript code with clang-format.')
parser.add_option('--diff', action='store_true',
@ -5154,6 +5153,11 @@ def CMDformat(parser, args):
help='Used when running the script from a presubmit.')
opts, args = parser.parse_args(args)
if opts.python is not None and opts.no_python:
raise parser.error('Cannot set both --python and --no-python')
if opts.no_python:
opts.python = False
# Normalize any remaining args against the current path, so paths relative to
# the current directory are still resolved as expected.
args = [os.path.join(os.getcwd(), arg) for arg in args]

Loading…
Cancel
Save