Project

Profile

Help

How to connect?
Download (3.95 KB) Statistics
| Branch: | Revision:

he / hooks / pre-commit @ saxon10

1
#!/bin/bash
2

    
3
if git rev-parse --verify HEAD >/dev/null 2>&1
4
then
5
	against=HEAD
6
else
7
	# Initial commit: diff against an empty tree object
8
	against=$(git hash-object -t tree /dev/null)
9
fi
10

    
11
# Redirect output to stderr.
12
exec 1>&2
13

    
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
COMMERCIAL=(src/main/java/com src/main/java/javax)
18

    
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
27
ALLFILES=0
28
COMMFILES=0
29
EXFILES=0
30

    
31
# Keep track of the names of exemplar files from each category
32
AFILE=none
33
CFILE=none
34
EFILE=none
35

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

    
41
    # Consider all the commercial prefixes
42
    ISCOMM=0
43
    for prefix in ${COMMERCIAL[*]}; do
44
        if [[ $fn == ${prefix}* ]]; then
45
            # This filename begins with a commercial prefix, so
46
            # there's at least one commercial file in this commit.
47
            ISCOMM=1
48
            if [ "X$CFILE" == "Xnone" ]; then
49
                CFILE="$fn"
50
            fi
51
        fi            
52
    done
53
    if [ $ISCOMM != 0 ]; then
54
        # Count the commercial files
55
        COMMFILES=`expr $COMMFILES + 1`
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.
80
        if [ "X$AFILE" == "Xnone" ]; then
81
            AFILE="$fn"
82
        fi
83
    fi
84
done
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

    
109
# If there's at least one commercial file, and they aren't *all*
110
# commercial files, then this is a mixed commit: computer says no!
111
if [ $COMMFILES != 0 -a $ALLFILES != $COMMFILES ]; then
112
    cat <<EOF
113
** ERROR ***********************************************************
114
Commits to this repository are automatically mirrored to the open
115
source and commercial repositories. You may not have both commercial
116
and non-commercial files in the same commit. This commit attempt
117
includes at least one non-commercial file:
118
  $AFILE
119
and at least one commercial file:
120
  $CFILE
121
Please split this commit into at two commits with no commercial and
122
non-commercial files in a single commit.
123
********************************************************************
124
EOF
125
    exit 1;
126
fi
    (1-1/1)