Browse Source

feat: convenience command to apply all formatter patches (#14994)

* feat: convenience to apply all formatter patches

run-clang-format.py can create multiple patchfiles.
This change prints a command that can be pasted into
a shell to apply all of them together.

* feat: put all generated style diffs in one file

This way it will be easier to `git apply` fixes to multiple
fixed files at once.
Charles Kerr 6 years ago
parent
commit
e9a5b19223
1 changed files with 13 additions and 6 deletions
  1. 13 6
      script/run-clang-format.py

+ 13 - 6
script/run-clang-format.py

@@ -281,6 +281,9 @@ def main():
         njobs = multiprocessing.cpu_count() + 1
     njobs = min(len(files), njobs)
 
+    patch_file = tempfile.NamedTemporaryFile(delete=False,
+                                             prefix='electron-format-')
+
     if njobs == 1:
         # execute directly instead of in a pool,
         # less overhead, simpler stacktraces
@@ -315,14 +318,18 @@ def main():
                 continue
             if not args.quiet:
                 print_diff(outs, use_color=colored_stdout)
-                with tempfile.NamedTemporaryFile(delete=False) as patch_file:
-                    for line in outs:
-                        patch_file.write(line)
-                    patch_file.write('\n')
-                    print("\nTo apply this patch, run:\n$ git apply {}\n"
-                          .format(patch_file.name))
+                for line in outs:
+                    patch_file.write(line)
+                patch_file.write('\n')
             if retcode == ExitStatus.SUCCESS:
                 retcode = ExitStatus.DIFF
+
+    if patch_file.tell() == 0:
+      os.unlink(patch_file.name)
+    else:
+      print("\nTo patch these files, run:\n$ git apply {}\n"
+            .format(patch_file.name))
+
     return retcode