-
-
Save wzxjohn/683c6d5eef6f52da0872 to your computer and use it in GitHub Desktop.
pre-receive hook to deny pushing big files
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/perl -wl | |
use strict; | |
my $limit = 1024 * 1024; | |
my $hasBadFiles; | |
while (<>) { | |
chomp; | |
my ($old, $new, $ref) = split / /, $_; | |
my $log = ($old =~ /^0+$/ ? `git log --pretty=%H` : `git log --pretty=%H $old..$new`); | |
for my $commit (split /\n/, $log) { | |
for my $blob (split /\n/, `git ls-tree -l -r $commit`) { | |
my (undef, $type, undef, $size, $name) = split /\s+/, $blob; | |
next if $type ne 'blob'; | |
if ($size > $limit) { | |
print "Size of file '$name' in commit $commit is over limit ($limit bytes)"; | |
$hasBadFiles = 1; | |
} | |
} | |
} | |
} | |
$hasBadFiles and exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment