Skip to content

Instantly share code, notes, and snippets.

@youcune
Last active January 1, 2016 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youcune/8107996 to your computer and use it in GitHub Desktop.
Save youcune/8107996 to your computer and use it in GitHub Desktop.
git commitしたときに全角チルダが含まれていたらコミットを拒否する。EUC/UTF-8対応。Windowsで見ると全角チルダが化けてしまうためチェックスクリプト化しました。.git/hooks/pre-commitに設置して使います。
#!/usr/bin/env perl
# git commitしたときに全角チルダが含まれていたらコミットを拒否する
# \x8F\xA2\xB7 : EUC-JPで全角チルダ
# \xEF\xBD\x9E : UTF-8で全角チルダ
use strict;
use warnings;
our @files = `git diff-index --name-status HEAD | cut -c3-`;
foreach my $file (@files){
chomp($file);
open(IN, $file);
my $i = 1;
while(<IN>){
die "[Rejected] $file contains illegal character(s) at line $i\n" if /\x8F\xA2\xB7|\xEF\xBD\x9E/;
$i ++;
}
close(IN);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment