Project

Profile

Help

Revision c5504920

Added by Norman Tovey-Walsh 10 months ago

Make this hook the same as main

View differences:

hooks/pre-commit
11 11
# Redirect output to stderr.
12 12
exec 1>&2
13 13

  
14
# Files and directories that begin with these prefixes are
15
# considered commercial and must be in separate commits
16
# from files that are non-commercial
14
# Files and directories that begin with these prefixes are considered
15
# commercial and must be in separate commits from files that are
16
# non-commercial
17 17
COMMERCIAL=(src/main/java/com src/main/java/javax)
18 18

  
19
# Count all the files and all the commercial files
19
# Files and directories that begin with these prefixes will be
20
# excluded from mirroring. (Update the mirror script as well if you
21
# change this list!) Files that begin with these prefixes must be
22
# in separate commits from all other files.
23
EXCLUDE=(src/test/bugs src/test/nunit src/test/xmark)
24

  
25
# Count all the files, all the commercial files, and all the excluded
26
# files
20 27
ALLFILES=0
21 28
COMMFILES=0
29
EXFILES=0
22 30

  
23
# Keep track of the names of exemplar non-commercial
24
# and commercial files
31
# Keep track of the names of exemplar files from each category
25 32
AFILE=none
26 33
CFILE=none
34
EFILE=none
27 35

  
28 36
# Loop over all the files in this commit...
29 37
for fn in `git diff --cached --name-only`; do
30 38
    # Count all the files
31 39
    ALLFILES=`expr $ALLFILES + 1`
32 40

  
33
    # Consider all the commercial prexies
41
    # Consider all the commercial prefixes
34 42
    ISCOMM=0
35 43
    for prefix in ${COMMERCIAL[*]}; do
36 44
        if [[ $fn == ${prefix}* ]]; then
37
            # If this filename begins with a commercial prefix,
38
            # then there's at least one commercial file in this
39
            # commit.
45
            # This filename begins with a commercial prefix, so
46
            # there's at least one commercial file in this commit.
40 47
            ISCOMM=1
41 48
            if [ "X$CFILE" == "Xnone" ]; then
42 49
                CFILE="$fn"
43 50
            fi
44 51
        fi            
45 52
    done
46

  
47 53
    if [ $ISCOMM != 0 ]; then
48 54
        # Count the commercial files
49 55
        COMMFILES=`expr $COMMFILES + 1`
50
    else
51
        # If none of the commercial prefixes matched,
52
        # then there's at least one non-commercial file
53
        # in this commit.
56
    fi
57

  
58
    # Consider all the excluded prefixes
59
    ISEXCL=0
60
    if [ $ISCOMM = 0 ]; then
61
        for prefix in ${EXCLUDE[*]}; do
62
            if [[ $fn == ${prefix}* ]]; then
63
                # This filename begins with an exclude prefix, so
64
                # there's at least one excluded file in this commit.
65
                ISEXCL=1
66
                if [ "X$EFILE" == "Xnone" ]; then
67
                    EFILE="$fn"
68
                fi
69
            fi            
70
        done
71
        if [ $ISEXCL != 0 ]; then
72
            # Count the excluded files
73
            EXFILES=`expr $EXFILES + 1`
74
        fi
75
    fi
76

  
77
    if [ $ISCOMM = 0 -a $ISEXCL = 0 ]; then
78
        # If none of the commercial or exclude prefixes matched, then
79
        # there's at least one non-commercial file in this commit.
54 80
        if [ "X$AFILE" == "Xnone" ]; then
55 81
            AFILE="$fn"
56 82
        fi
57 83
    fi
58 84
done
59 85

  
86
# If there's at least one excluded file, and they aren't *all*
87
# excluded files, then this is a mixed commit: computer says no!
88
if [ $EXFILES != 0 -a $ALLFILES != $EXFILES ]; then
89
    NEFILE=$CFILE
90
    if [ "X$AFILE" != "Xnone" ]; then
91
        NEFILE=$AFILE
92
    fi
93
    cat <<EOF
94
** ERROR ***********************************************************
95
Commits to this repository are automatically mirrored to the open
96
source and commercial repositories. Some directories are excluded:
97
${EXCLUDE[*]}
98
This commit attempt includes at least one excluded file:
99
  $EFILE
100
and at least one non-excluded file:
101
  $NEFILE
102
Please split this commit into at two commits with no excluded and
103
non-excluded files in a single commit.
104
********************************************************************
105
EOF
106
    exit 1;
107
fi
108

  
60 109
# If there's at least one commercial file, and they aren't *all*
61 110
# commercial files, then this is a mixed commit: computer says no!
62 111
if [ $COMMFILES != 0 -a $ALLFILES != $COMMFILES ]; then

Also available in: Unified diff