Just wanted to share a git hook I'm using to automatically apply hlint
to Haskell files that I'm commiting.

First all I'm using the existing pre-commit example that git provides
(.git/hooks/pre-commit.sample). Just copy that file to
.git/hooks/pre-commit and `chmod 755` it.

Then I chained an hlint check to the whitespace check:

--- .git/hooks/pre-commit.sample        2016-07-14 09:56:25.509776550 +0300
+++ .git/hooks/pre-commit       2016-07-22 12:23:12.997344972 +0300
@@ -46,4 +46,11 @@
 # If there are whitespace errors, print the offending file names and fail.
-exec git diff-index --check --cached $against --
+if git diff-index --check --cached $against --
+    # Otherwise, if Haskell files have changed, run hlint on them.
+    changedHaskell=$(git diff-index --diff-filter=ACMR --numstat --cached 
$against -- '*.hs' | cut -f3)
+    exec ${changedHaskell:+hlint -XQuasiQuotes $changedHaskell}
+    exit 1

Honestly I bet there's a nicer way to get the list of changed Haskell
files, but git is weird.

Attachment: signature.asc
Description: Digital signature

Dev mailing list

Reply via email to