-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
39 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /bin/sh | ||
# | ||
# This script ensures Crystal code is correctly formatted before committing it. | ||
# It won't apply any format changes automatically. | ||
# | ||
# Only staged files (the ones to be committed) are being processed, but each file is checked | ||
# entirely as it is stored on disc, even parts that are not staged. | ||
# | ||
# To use this script, it needs to be installed in the local git repository. For example by running | ||
# `ln -s scripts/git/pre-commit .git/hooks` in the root folder. | ||
# | ||
# Called by "git commit" with no arguments. The hook should | ||
# exit with non-zero status after issuing an appropriate message if | ||
# it wants to stop the commit. | ||
|
||
changed_cr_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.cr$') | ||
|
||
[ -z "$changed_cr_files" ] && exit 0 | ||
|
||
if [ -x bin/crystal ]; then | ||
# use bin/crystal wrapper when available to run local compiler build | ||
exec bin/crystal tool format --check $changed_cr_files >&2 | ||
else | ||
exec crystal tool format --check $changed_cr_files >&2 | ||
fi |
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
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