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: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 7f87417..fe0c00f 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -5133,6 +5133,12 @@
   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',
       default=None,
@@ -5145,8 +5151,11 @@
       '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 @@
   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)]