Skip to content

Instantly share code, notes, and snippets.

@shogo82148
Created January 28, 2018 14:53
Show Gist options
  • Save shogo82148/44741f486f53d14e0144539cf726b91c to your computer and use it in GitHub Desktop.
Save shogo82148/44741f486f53d14e0144539cf726b91c to your computer and use it in GitHub Desktop.
pre-commit
#!/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