Created
January 28, 2018 14:53
-
-
Save shogo82148/44741f486f53d14e0144539cf726b91c to your computer and use it in GitHub Desktop.
pre-commit
This file contains hidden or 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
#!/usr/bin/env perl | |
use utf8; | |
use strict; | |
use warnings; | |
use Encode qw/encode_utf8 decode_utf8/; | |
my $against = "HEAD"; | |
if ( system("git rev-parse --verify HEAD >/dev/null 2>&1") != 0 ) { | |
# Initial commit: diff against an empty tree object | |
$against = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" | |
} | |
my $diff = decode_utf8(`git diff --cached $against | grep ^\\+`); | |
if ($diff =~ /\N{U+FFFD}/) { | |
print encode_utf8("不正な文字が混ざっています!\n"); | |
exit 1; | |
} | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment