Don't install commit hook if not in a git repo

This occurs, for example, if SwiftShader is checked out as a submodule.

Change-Id: Ie9b8962cdc4a5f20f33c8b6e911da05cd7a6ee13
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/73428
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Geoff Lang <geofflang@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c5cd16d..22ebba1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -116,7 +116,7 @@
 # Install Gerrit commit hook
 ###########################################################
 
-if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg)
+if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git AND NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg)
     message(WARNING "
         .git/hooks/commit-msg was not found.
         Downloading from https://gerrit-review.googlesource.com/tools/hooks/commit-msg...