Commit 91a6f338 authored by Garrett Beaty's avatar Garrett Beaty Committed by Commit Bot

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: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
parent ecc27074
...@@ -5140,12 +5140,11 @@ def CMDformat(parser, args): ...@@ -5140,12 +5140,11 @@ def CMDformat(parser, args):
parser.add_option( parser.add_option(
'--no-python', '--no-python',
action='store_true', action='store_true',
dest='python', default=False,
help='Disables python formatting on all python files. ' 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 '
'If neither --python or --no-python are set, python ' '.style.yapf file in an ancestor directory will be formatted. '
'files that have a .style.yapf file in an ancestor ' 'It is an error to set both.')
'directory will be formatted.')
parser.add_option('--js', action='store_true', parser.add_option('--js', action='store_true',
help='Format javascript code with clang-format.') help='Format javascript code with clang-format.')
parser.add_option('--diff', action='store_true', parser.add_option('--diff', action='store_true',
...@@ -5154,6 +5153,11 @@ def CMDformat(parser, args): ...@@ -5154,6 +5153,11 @@ def CMDformat(parser, args):
help='Used when running the script from a presubmit.') help='Used when running the script from a presubmit.')
opts, args = parser.parse_args(args) 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 # Normalize any remaining args against the current path, so paths relative to
# the current directory are still resolved as expected. # the current directory are still resolved as expected.
args = [os.path.join(os.getcwd(), arg) for arg in args] args = [os.path.join(os.getcwd(), arg) for arg in args]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment