Commit ed0cc5f6 authored by Garrett Beaty's avatar Garrett Beaty Committed by Commit Bot

Add flag to "git cl format" to avoid invoking clang-format.

In repos that are checked out separately from chromium, invoking
"git cl format" on a change that has files that would be formatted using
clang-format causes an error because the depot_tools version of
clang-format looks for a clang-format inside the repo.

This prevents using proto-based properties (the preferred mechanism
going forward) in recipe repos that enforce formatting. The
--no-clang-format flag provides a workaround that can be used to
prevent trying to format any files where clang-format doesn't work.

Bug: 979330
Change-Id: Ice8561d88b29623deb953465253f92c88aa7fc2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1986111
Commit-Queue: Garrett Beaty <gbeaty@chromium.org>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
parent 91a6f338
......@@ -5132,6 +5132,12 @@ def CMDformat(parser, args):
help='Reformat the full content of all touched files')
parser.add_option('--dry-run', action='store_true',
help='Don\'t modify any file on disk.')
parser.add_option(
'--no-clang-format',
dest='clang_format',
action='store_false',
default=True,
help='Disables formatting of various file types using clang-format.')
parser.add_option(
'--python',
action='store_true',
......@@ -5145,8 +5151,11 @@ def CMDformat(parser, args):
'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(
'--js',
action='store_true',
help='Format javascript code with clang-format. '
'Has no effect if --no-clang-format is set.')
parser.add_option('--diff', action='store_true',
help='Print diff to stdout rather than modifying files.')
parser.add_option('--presubmit', action='store_true',
......@@ -5192,7 +5201,11 @@ def CMDformat(parser, args):
if opts.js:
CLANG_EXTS.extend(['.js', '.ts'])
clang_diff_files = [x for x in diff_files if MatchingFileType(x, CLANG_EXTS)]
clang_diff_files = []
if opts.clang_format:
clang_diff_files = [
x for x in diff_files if MatchingFileType(x, CLANG_EXTS)
]
python_diff_files = [x for x in diff_files if MatchingFileType(x, ['.py'])]
dart_diff_files = [x for x in diff_files if MatchingFileType(x, ['.dart'])]
gn_diff_files = [x for x in diff_files if MatchingFileType(x, GN_EXTS)]
......
......@@ -1214,6 +1214,7 @@ def PanProjectChecks(input_api, output_api,
def CheckPatchFormatted(input_api,
output_api,
bypass_warnings=True,
check_clang_format=True,
check_js=False,
check_python=None,
result_factory=None):
......@@ -1221,6 +1222,9 @@ def CheckPatchFormatted(input_api,
import git_cl
display_args = []
if not check_clang_format:
display_args.append('--no-clang-format')
if check_js:
display_args.append('--js')
......
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