File: checkcommit

package info (click to toggle)
crawl 2%3A0.33.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,264 kB
  • sloc: cpp: 358,145; ansic: 27,203; javascript: 9,491; python: 8,359; perl: 3,327; java: 2,667; xml: 2,191; makefile: 1,830; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (78 lines) | stat: -rwxr-xr-x 1,879 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env perl

use warnings;
use strict;
use Encode;

## Checks the commit diff for suspicious lines not covered by util/checkwhite
## and util/unbrace, namely unresolved merges.

open DIFF, "git diff-index -p -M --cached HEAD --|"
    or die "pre-commit: Can't obtain the diff. Run git commit -n to ignore.\n";

my $found_bad = 0;
my $filename;
my $reported_filename = "";
my $lineno;
my $lastadd = 0; # a terrible hack
my $skip = 0;

sub bad_line
{
    return if $skip;
    my ($why, $noquote) = @_;
    if (!$found_bad)
    {
        print STDERR "*\n";
        print STDERR "* You have some suspicious patch lines:\n";
        print STDERR "*\n";
        $found_bad = 1;
    }
    if ($reported_filename ne $filename)
    {
        print STDERR "* $filename\n";
        $reported_filename = $filename;
    }
    print STDERR "  + $why (line $lineno)\n";
    #print STDERR "$_\n" unless $noquote;
}

while (<DIFF>)
{
    if (m|^diff --git a/(.*) b/\1$|)
    {
        $filename = $1;

        $skip = $filename =~ /\.(png|gif|ttf|ico|icns|fig|tex|eps|pdf)$/i
             || $filename =~ /\.(sln|vim|pbxproj|vsprops|plist|csproj|config|cs)$/i
             || $filename =~ /\.(vcproj|vcproj\.user|vcxproj|vcxproj\.filters)$/i
             || $filename =~ /^\.gitmodules$/
             || $filename =~ /\.(lex|tab)\./
             || $filename !~ /\./;
        next;
    }
    if (/^@@ -\S+ \+(\d+)/)
    {
        $lineno = $1 - 1;
        next;
    }
    if (/^ /)
    {
        $lineno++;
        next;
    }
    if (s/^\+//)
    {
        $lineno++;
        chomp;
        bad_line("unresolved merge conflict") if /^([<>])\1{6} |^={7}$/;
    }
    $lastadd = $lineno if $_ eq "";
}

if ($found_bad)
{
    print STDERR "\nPlease correct or, if it's a false positive,\n".
                 "commit -n to ignore. In that case, please report it as a bug.\n";
    exit 1;
}