From f0092d3bb2ebeff94835ceab6e0bead58d35a349 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 22 Nov 2011 20:10:12 +0100 Subject: detect ELF (and PE) files as generated files by content ELF exes typically have no extension, so they have no filename check. (cherry picked from commit 1ca6a72aaa2b1f12ef5ec4b46a3976fffdd866c9) --- git-hooks/sanitize-commit | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/git-hooks/sanitize-commit b/git-hooks/sanitize-commit index 78f434d..cbaf213 100755 --- a/git-hooks/sanitize-commit +++ b/git-hooks/sanitize-commit @@ -211,6 +211,13 @@ sub formatSize($) } } +sub isExe($) +{ + my $sha = shift; + my $type = `git cat-file -p $sha | file -b -`; + return $type =~ /^(ELF|PE32) /; +} + my @style_fails = (); sub styleFail($) @@ -347,7 +354,7 @@ while () { } if ($maybe_bin && /^Binary files /) { if ($new_file) { - if (!defined($cfg{generated}) && $file =~ /\.(obj|o|lib|a|dll|so|exe|exp|qm|pdb|idb|suo)$/i) { + if (!defined($cfg{generated}) && ($file =~ /\.(obj|o|lib|a|dll|so|exe|exp|qm|pdb|idb|suo)$/i || isExe($maybe_bin))) { &complain("Adding build artifact", "generated"); } } else { @@ -395,7 +402,7 @@ while () { formatSize($old_size)." => ".formatSize($size).")", "size"); } } - $maybe_bin = 1; + $maybe_bin = $new_tree; next; } } -- cgit v1.2.1