summaryrefslogtreecommitdiffstats
path: root/src/VREF/COUNT
blob: f4c3eae4d4d9aca029824b9811570f6c82d264c2 (plain)
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
#!/bin/sh

# gitolite VREF to count number of changed/new files in a push

# see gitolite docs for what the first 7 arguments mean

# inputs:
#   arg-8 is a number
#   arg-9 is optional, and can be "NEWFILES"
# outputs (STDOUT)
#   arg-7 if the number of changed (or new, if arg-9 supplied) files is > arg-8
#   otherwise nothing
# exit status:
#   always 0

die() { echo "$@" >&2; exit 1; }
[ -z "$8" ] && die "not meant to be run manually"

newsha=$3
oldtree=$4
newtree=$5
refex=$7

max=$8

nf=
[ "$9" = "NEWFILES" ] && nf='--diff-filter=A'
# NO_SIGNOFF implies NEWFILES
[ "$9" = "NO_SIGNOFF" ] && nf='--diff-filter=A'

# count files against all the other commits in the system not just $oldsha
# (why?  consider what is $oldtree when you create a new branch, or what is
# $oldsha when you update an old feature branch from master and then push it
count=`git log --name-only $nf --format=%n $newtree --not --all | grep . | sort -u | perl -ne '}{print "$."'`

[ $count -gt $max ] && {
    # count has been exceeded.  If $9 was NO_SIGNOFF there's still a chance
    # for redemption -- if the top commit has a proper signed-off by line
    [ "$9" = "NO_SIGNOFF" ] && {
        author_email=$(git log --format=%ae -1 $newsha)
        git cat-file -p $newsha |
            egrep -i >/dev/null "^ *$count +new +files +signed-off by: *$author_email *$" && exit 0
        echo $refex top commit message should include the text \'$count new files signed-off by: $author_email\'
        exit 0
    }
    echo -n $refex "(too many "
    [ -n "$nf" ] && echo -n "new " || echo -n "changed "
    echo "files in this push)"
}

exit 0