Precommit hook: just warn if no clang-tidy (#15514)
authorMichael Suo <suo@fb.com>
Sun, 23 Dec 2018 22:35:41 +0000 (14:35 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 23 Dec 2018 22:38:13 +0000 (14:38 -0800)
Summary:
The precommit hook shouldn't hard fail if there's no `clang-tidy`, just warn and omit the check.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15514

Differential Revision: D13545776

Pulled By: suo

fbshipit-source-id: 9bf3f8ee18703c6d1a39eb7776092fb5e120d2a1

tools/git-pre-commit

index 81983a4..d11b646 100755 (executable)
@@ -2,13 +2,21 @@
 set -e
 echo "Running pre-commit flake8"
 python tools/flake8_hook.py
-echo "Running pre-commit clang-tidy"
-python tools/clang_tidy.py \
-  --paths torch/csrc \
-  --diff HEAD \
-  -g"-torch/csrc/distributed/Module.cpp" \
-  -g"-torch/csrc/jit/export.cpp" \
-  -g"-torch/csrc/jit/import.cpp" \
-  -j
+
+if [ $(which clang-tidy) ]
+then
+  echo "Running pre-commit clang-tidy"
+  python tools/clang_tidy.py \
+    --paths torch/csrc \
+    --diff HEAD \
+    -g"-torch/csrc/distributed/Module.cpp" \
+    -g"-torch/csrc/jit/export.cpp" \
+    -g"-torch/csrc/jit/import.cpp" \
+    -j
+else
+  echo "WARNING: Couldn't find clang-tidy executable."
+  echo "  Please install it if you want local clang-tidy checks."
+fi
+
 echo "Running pre-commit clang-format"
 python tools/clang_format.py