This repository has been archived by the owner on May 17, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supply a Git pre-commit hook for tools/check-typo
Automatically runs tools/check-typo and rejects the commit if they don't pass.
- Loading branch information
Showing
4 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
#************************************************************************** | ||
#* * | ||
#* OCaml * | ||
#* * | ||
#* David Allsopp, MetaStack Solutions Ltd. * | ||
#* * | ||
#* Copyright 2017 MetaStack Solutions Ltd. * | ||
#* * | ||
#* All rights reserved. This file is distributed under the terms of * | ||
#* the GNU Lesser General Public License version 2.1, with the * | ||
#* special exception on linking described in the file LICENSE. * | ||
#* * | ||
#************************************************************************** | ||
|
||
# For what it's worth, allow for empty trees! | ||
if git rev-parse --verify HEAD >/dev/null 2>&1 | ||
then | ||
against=HEAD | ||
else | ||
# Initial commit: diff against an empty tree object | ||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ||
fi | ||
|
||
# Redirect output to stderr. | ||
exec 1>&2 | ||
|
||
# Git's built-in mechanism for whitespace is neater than ours, so do it first. | ||
# The strange construction below creates a list of files which have either | ||
# white-at-eol or white-at-eof included in ocaml-typo in .gitattributes and by | ||
# prefixing the names with :! causes git diff-index to skip over them. | ||
FILES=$(git diff-index --cached --name-only $against \ | ||
| xargs git check-attr --cached ocaml-typo \ | ||
| sed -ne 's/\(.*\): ocaml-typo:.*[ ,]white-at-eo[fl]\(,\|$\)/:!\1/p') | ||
if ! git diff-index --check --cached $against -- $FILES ; then | ||
exit 1 | ||
fi | ||
|
||
# Now run check-typo over all the files in the index | ||
ERRORS=0 | ||
export OCAML_CT_PREFIX=: | ||
export OCAML_CT_CAT="git cat-file --textconv" | ||
export OCAML_CT_CA_FLAG=--cached | ||
git diff --staged --name-only | (while IFS= read -r path | ||
do | ||
if ! tools/check-typo $path ; then | ||
ERRORS=1 | ||
fi | ||
done; exit $ERRORS) |