Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 112 lines (91 sloc) 3.425 kb
e7cefbba »
2012-02-16 Rest of the files, including tests for the hooks and the gate configu…
1 #!/bin/bash
2 #
3 # Copyright (c) 2012 by Delphix.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # - Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # - Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions and the following disclaimer in the documentation
13 # and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #
26
27 hooks=/delphix-gate/tools/git/hooks
28
29 function usage
30 {
31 if [[ $# -ne 0 ]]; then
32 echo "$(basename $0): $*" >&2
33 echo
34 fi
35
36 cat <<EOF
37 Usage: $(basename $0) [-bBcCrR] [-d dir] <notification-address> ..."
38
39 -b/B enable/disable bug checks (enabled by default)
40 -c/C enable/disable comment checks (enabled by default)
41 -r/R enable/disable review checks (disabled by default)
42
43 -d dir specify the git hooks directory; default:
44 $hooks
45
46 Execute this from the root of a git repository that you want to
47 configure as a project gate with emails sent to the given addresses.
48 EOF
49
50 exit 2
51 }
52
53 function die
54 {
55 echo "$(basename $0): $*" >&2
56 exit 1
57 }
58
59 opt_b=true # bug checks are enabled by default
60 opt_c=true # comment checks are enabled by default
61 opt_r=false # review checks are disabled by default
62
63 OPTIND=1; while getopts 'bBcCd:rRh' c; do
64 case "$c" in
65 b|c|r) eval opt_$c=true ;;
66 B|C|R) eval "opt_$(echo $c | tr '[:upper:]' '[:lower:]')=false" ;;
67 d) hooks="$OPTARG" ;;
68 h) usage ;;
69 *) usage ;;
70 esac
71 done
72
73 let OPTIND="$OPTIND - 1"; shift $OPTIND
74
75 [[ $# -gt 0 ]] || usage
76
77 $opt_r && ($opt_b || usage "Review checks (-r) require bug checks (-b)")
78 $opt_b && ($opt_c || usage "Bug checks (-b) require comment checks (-c)")
79
80 base=$(git rev-parse --show-toplevel 2>/dev/null)
81 [[ $? -eq 0 ]] || die "Must be run from a git repository"
82 [[ $(pwd -P) = $base ]] || die "Must be run from the top-level directory"
83
84
85 git config --get gate.name >/dev/null 2>&1 && \
86 die ".git/config is already configured as a gate"
87
88 cp -r $hooks .git/newhooks || die "failed to copy $hooks"
89 rm -rf .git/hooks || die "failed to remove old hooks"
90 mv .git/newhooks .git/hooks || die "failed to rename new hooks"
91
92 cat <<EOF >.git/config
93 [core]
94 repositoryformatversion = 0
95 filemode = true
96 bare = false
97 logallrefupdates = true
98 [receive]
99 denyCurrentBranch = ignore
100 [gate]
101 name = $(basename $base)
102 notify = $*
103 # user-check = skip
104 $($opt_c && echo "# ")commit-check = skip
105 $($opt_b && echo "# ")comment-check = skip
106 $($opt_r && echo "# ")review-check = skip
107 EOF
108
109 echo "Your gate has been configured"
110
111 exit 0
Something went wrong with that request. Please try again.