Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rest of the files, including tests for the hooks and the gate configu…

…rator.
  • Loading branch information...
commit e7cefbbae57f8eef7ff525c7695b929d888b4866 1 parent 249af6c
@zukhan zukhan authored
Showing with 554 additions and 0 deletions.
  1. +111 −0 setup-gate.sh
  2. +12 −0 test/configs/err.badbugsummary.cfg
  3. +7 −0 test/configs/err.badbugsummary.cfg.out
  4. +10 −0 test/configs/err.badcomment.cfg
  5. +6 −0 test/configs/err.badcomment.cfg.out
  6. +8 −0 test/configs/err.badname.cfg
  7. +4 −0 test/configs/err.badname.cfg.out
  8. +9 −0 test/configs/err.baduser.cfg
  9. +1 −0  test/configs/err.baduser.cfg.out
  10. +14 −0 test/configs/err.basebadbugsummary.cfg
  11. +6 −0 test/configs/err.basebadbugsummary.cfg.out
  12. +22 −0 test/configs/err.mixednoreview.cfg
  13. +1 −0  test/configs/err.mixednoreview.cfg.out
  14. +6 −0 test/configs/err.noname.cfg
  15. +4 −0 test/configs/err.noname.cfg.out
  16. +8 −0 test/configs/err.nonotify.cfg
  17. +4 −0 test/configs/err.nonotify.cfg.out
  18. +12 −0 test/configs/err.noreview.cfg
  19. +1 −0  test/configs/err.noreview.cfg.out
  20. +23 −0 test/configs/tst.docappmix.cfg
  21. +7 −0 test/configs/tst.docappmix.cfg.out
  22. +22 −0 test/configs/tst.doconly.cfg
  23. +5 −0 test/configs/tst.doconly.cfg.out
  24. +5 −0 test/configs/tst.doconly.out
  25. +17 −0 test/configs/tst.projectbugsnoshorty.cfg
  26. +4 −0 test/configs/tst.projectbugsnoshorty.cfg.out
  27. +19 −0 test/configs/tst.projectgate.cfg
  28. +6 −0 test/configs/tst.projectgate.cfg.out
  29. +19 −0 test/configs/tst.projectgatenoshorty.cfg
  30. +6 −0 test/configs/tst.projectgatenoshorty.cfg.out
  31. +175 −0 test/testhooks.sh
View
111 setup-gate.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+#
+# Copyright (c) 2012 by Delphix.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+hooks=/delphix-gate/tools/git/hooks
+
+function usage
+{
+ if [[ $# -ne 0 ]]; then
+ echo "$(basename $0): $*" >&2
+ echo
+ fi
+
+ cat <<EOF
+Usage: $(basename $0) [-bBcCrR] [-d dir] <notification-address> ..."
+
+ -b/B enable/disable bug checks (enabled by default)
+ -c/C enable/disable comment checks (enabled by default)
+ -r/R enable/disable review checks (disabled by default)
+
+ -d dir specify the git hooks directory; default:
+ $hooks
+
+Execute this from the root of a git repository that you want to
+configure as a project gate with emails sent to the given addresses.
+EOF
+
+ exit 2
+}
+
+function die
+{
+ echo "$(basename $0): $*" >&2
+ exit 1
+}
+
+opt_b=true # bug checks are enabled by default
+opt_c=true # comment checks are enabled by default
+opt_r=false # review checks are disabled by default
+
+OPTIND=1; while getopts 'bBcCd:rRh' c; do
+ case "$c" in
+ b|c|r) eval opt_$c=true ;;
+ B|C|R) eval "opt_$(echo $c | tr '[:upper:]' '[:lower:]')=false" ;;
+ d) hooks="$OPTARG" ;;
+ h) usage ;;
+ *) usage ;;
+ esac
+done
+
+let OPTIND="$OPTIND - 1"; shift $OPTIND
+
+[[ $# -gt 0 ]] || usage
+
+$opt_r && ($opt_b || usage "Review checks (-r) require bug checks (-b)")
+$opt_b && ($opt_c || usage "Bug checks (-b) require comment checks (-c)")
+
+base=$(git rev-parse --show-toplevel 2>/dev/null)
+[[ $? -eq 0 ]] || die "Must be run from a git repository"
+[[ $(pwd -P) = $base ]] || die "Must be run from the top-level directory"
+
+
+git config --get gate.name >/dev/null 2>&1 && \
+ die ".git/config is already configured as a gate"
+
+cp -r $hooks .git/newhooks || die "failed to copy $hooks"
+rm -rf .git/hooks || die "failed to remove old hooks"
+mv .git/newhooks .git/hooks || die "failed to rename new hooks"
+
+cat <<EOF >.git/config
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = $(basename $base)
+ notify = $*
+ # user-check = skip
+ $($opt_c && echo "# ")commit-check = skip
+ $($opt_b && echo "# ")comment-check = skip
+ $($opt_r && echo "# ")review-check = skip
+EOF
+
+echo "Your gate has been configured"
+
+exit 0
View
12 test/configs/err.badbugsummary.cfg
@@ -0,0 +1,12 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+[test]
+ comment = 1234 invalid bug summary
View
7 test/configs/err.badbugsummary.cfg.out
@@ -0,0 +1,7 @@
+remote: Bug summaries must match with data in Bugzilla
+remote: - 1234 invalid bug summary
+remote: + 1234 Top Search on Logo/Menu bar - "Search" Application
+remote:
+remote: Use the following command to edit the last commit message:
+remote: git commit --amend --reset-author
+remote:
View
10 test/configs/err.badcomment.cfg
@@ -0,0 +1,10 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
View
6 test/configs/err.badcomment.cfg.out
@@ -0,0 +1,6 @@
+remote: commit lines must be of the form <id> <summary>
+remote: > new file
+remote:
+remote: Use the following command to edit the last commit message:
+remote: git commit --amend --reset-author
+remote:
View
8 test/configs/err.badname.cfg
@@ -0,0 +1,8 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = delphix-gate
View
4 test/configs/err.badname.cfg.out
@@ -0,0 +1,4 @@
+remote:
+remote: The gate configuration lists delphix-gate rather than gate.
+remote: Contact the administrator or gatekeeper.
+remote:
View
9 test/configs/err.baduser.cfg
@@ -0,0 +1,9 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
View
1  test/configs/err.baduser.cfg.out
@@ -0,0 +1 @@
+remote: Must be the 'git' user to push
View
14 test/configs/err.basebadbugsummary.cfg
@@ -0,0 +1,14 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ comment-check = skip
+ review-check = skip
+[gate "the_epa"]
+ comment-check = yes
View
6 test/configs/err.basebadbugsummary.cfg.out
@@ -0,0 +1,6 @@
+remote: commit lines must be of the form <id> <summary>
+remote: > new file
+remote:
+remote: Use the following command to edit the last commit message:
+remote: git commit --amend --reset-author
+remote:
View
22 test/configs/err.mixednoreview.cfg
@@ -0,0 +1,22 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = gate
+ shortname = app
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ bug-update = skip
+ mail-debug = true
+[gate "doc"]
+ shortname = doc
+ notify = differentinvalidemailaddress@abadaddress
+ review-check = skip
+[test]
+ comment = 13408 remove mention of mirroring, raidz, and log devices
+ files = doc/foo doc/bar appliance/server/foo
View
1  test/configs/err.mixednoreview.cfg.out
@@ -0,0 +1 @@
+remote: ERROR: bug 13408 is not covered by a pending review
View
6 test/configs/err.noname.cfg
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
View
4 test/configs/err.noname.cfg.out
@@ -0,0 +1,4 @@
+remote:
+remote: This git repo has not been set up as a gate.
+remote: Contact the administrator or gatekeeper.
+remote:
View
8 test/configs/err.nonotify.cfg
@@ -0,0 +1,8 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = gate
View
4 test/configs/err.nonotify.cfg.out
@@ -0,0 +1,4 @@
+remote:
+remote: The gate configuration is missing a notification address.
+remote: Contact the administrator or gatekeeper.
+remote:
View
12 test/configs/err.noreview.cfg
@@ -0,0 +1,12 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+[test]
+ comment = 1234 Top Search on Logo/Menu bar - \"Search\" Application
View
1  test/configs/err.noreview.cfg.out
@@ -0,0 +1 @@
+remote: ERROR: bug 1234 is not covered by a pending review
View
23 test/configs/tst.docappmix.cfg
@@ -0,0 +1,23 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = gate
+ shortname = app
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ bug-update = skip
+ mail-debug = true
+ review-check = skip # note that this is just for the test; not the gate
+[gate "doc"]
+ shortname = doc
+ notify = differentinvalidemailaddress@abadaddress
+ review-check = skip
+[test]
+ comment = 13408 remove mention of mirroring, raidz, and log devices
+ files = doc/foo doc/bar appliance/server/foo
View
7 test/configs/tst.docappmix.cfg.out
@@ -0,0 +1,7 @@
+remote: changing file: appliance/server/foo
+remote: changing file: doc/bar
+remote: changing file: doc/foo
+remote: Checks successful.
+remote: differentinvalidemailaddress@abadaddress [gate] push to app (bugs 13408)
+remote: invalidemailaddress@abadaddress [gate] push to app (bugs 13408)
+remote: skipping bug update
View
22 test/configs/tst.doconly.cfg
@@ -0,0 +1,22 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = gate
+ shortname = app
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ bug-update = skip
+ mail-debug = true
+[gate "doc"]
+ shortname = doc
+ notify = differentinvalidemailaddress@abadaddress
+ review-check = skip
+[test]
+ comment = 13408 remove mention of mirroring, raidz, and log devices
+ files = doc/foo doc/bar
View
5 test/configs/tst.doconly.cfg.out
@@ -0,0 +1,5 @@
+remote: changing file: doc/bar
+remote: changing file: doc/foo
+remote: Checks successful.
+remote: differentinvalidemailaddress@abadaddress [gate] push to app (bugs 13408)
+remote: skipping bug update
View
5 test/configs/tst.doconly.out
@@ -0,0 +1,5 @@
+remote: changing file: doc/bar
+remote: changing file: doc/foo
+remote: Checks successful.
+remote: differentinvalidemailaddress@abadaddress [gate] push to app (bugs 13408)
+remote: skipping bug update
View
17 test/configs/tst.projectbugsnoshorty.cfg
@@ -0,0 +1,17 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ review-check = skip
+ bug-update = skip
+ mail-debug = true
+[test]
+ comment = 14273 git hooks should be more amenable to project gates
View
4 test/configs/tst.projectbugsnoshorty.cfg.out
@@ -0,0 +1,4 @@
+remote: changing file: the_epa
+remote: Checks successful.
+remote: invalidemailaddress@abadaddress [gate] push (bugs 14273)
+remote: skipping bug update
View
19 test/configs/tst.projectgate.cfg
@@ -0,0 +1,19 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = gate
+ shortname = app
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ comment-check = skip
+ review-check = skip
+ mail-debug = true
+[test]
+ comment = I love my project gate
+ files = doc/foo doc/bar appliance/server/foo
View
6 test/configs/tst.projectgate.cfg.out
@@ -0,0 +1,6 @@
+remote: changing file: appliance/server/foo
+remote: changing file: doc/bar
+remote: changing file: doc/foo
+remote: Checks successful.
+remote: invalidemailaddress@abadaddress [gate] push to app (I love my project gate)
+remote: skipping bug update
View
19 test/configs/tst.projectgatenoshorty.cfg
@@ -0,0 +1,19 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+[receive]
+ denyCurrentBranch = ignore
+[gate]
+ name = gate
+ notify = invalidemailaddress@abadaddress
+ user-check = skip
+ comment-check = skip
+ review-check = skip
+ bug-update = skip
+ mail-debug = true
+[test]
+ comment = I love my project gate
+ files = doc/foo doc/bar appliance/server/foo
View
6 test/configs/tst.projectgatenoshorty.cfg.out
@@ -0,0 +1,6 @@
+remote: changing file: appliance/server/foo
+remote: changing file: doc/bar
+remote: changing file: doc/foo
+remote: Checks successful.
+remote: invalidemailaddress@abadaddress [gate] push (I love my project gate)
+remote: skipping bug update
View
175 test/testhooks.sh
@@ -0,0 +1,175 @@
+#!/bin/bash
+#
+# Copyright (c) 2012 by Delphix.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+shopt -s xpg_echo
+
+tmp_dir=$(mktemp -d /tmp/githooks.XXXXXX)
+gate=$tmp_dir/gate
+work=$tmp_dir/work
+
+function die
+{
+ echo "$0: $*" >&2
+ echo " scratch space: $tmp_dir"
+ exit 1
+}
+
+function reset
+{
+ cd $gate
+ git reset --hard $head >/dev/null
+ cd - >/dev/null
+ cd $work
+ git reset --hard $head >/dev/null
+ cd - >/dev/null
+}
+
+function push
+{
+ local ret comment files file
+
+ cd $gate
+ comment=$(git config --get test.comment)
+ [[ -z "$comment" ]] && comment="new file"
+ files=$(git config --get test.files)
+ [[ -z "$files" ]] && files=the_epa
+ cd - >/dev/null
+
+ cd $work
+ for file in $files; do
+ [[ -d $(dirname $file) ]] || mkdir -p $(dirname $file)
+ done
+ touch $files
+ git add -f $files
+ git log >>/tmp/foo
+ git commit --quiet -m "$comment"
+ git log >>/tmp/foo
+ git push
+ ret=$?
+ cd - >/dev/null
+ return $ret
+}
+
+base=$(git rev-parse --show-toplevel 2>/dev/null)
+[[ $? -eq 0 ]] || die "not in a git repository"
+
+config_dir=$(dirname $0)/configs
+
+tests=$*
+[[ -z $tests ]] && tests=$(cd $config_dir; ls *)
+
+
+#
+# Create our test gate and link in our hooks.
+#
+echo "Creating test gate ... \c"
+mkdir $gate
+cd $gate
+git init --quiet --template=.././dev/null >/dev/null 2>&1 || \
+ dir "failed to git init"
+[[ -d "$base/tools/git/hooks" ]] || die "$base/tools/git/hooks doesn't exist"
+ln -s "$base/tools/git/hooks" $gate/.git
+touch dept_energy dept_transport um...
+git add .
+git commit --quiet -m "init"
+head=$(git show-ref --hash)
+cd - >/dev/null
+echo "done."
+
+#
+# As yet, there are no pull hooks, so we can pull once.
+#
+echo "Creating a clone ... \c"
+git clone --quiet $gate $work
+echo "done."
+
+echo
+total=0
+pass=0
+fail=0
+
+for test in $tests; do
+ [[ $test =~ ^err.*.cfg$ ]] || continue
+ reset
+ echo "$test ... \c"
+
+ cp $config_dir/$test $gate/.git/config || die "cp failed"
+ push > >(grep remote: >$tmp_dir/$test.out) 2>&1
+ err=$?
+
+ if [[ $err -eq 0 ]]; then
+ echo "failed: expected failure"
+ fail=$(($fail + 1))
+ elif [[ $err -ne 1 ]]; then
+ echo "failed: unexpected code $err"
+ fail=$(($fail + 1))
+ elif diff $config_dir/$test.out $tmp_dir/$test.out >/dev/null 2>&1; then
+ echo "passed."
+ pass=$(($pass + 1))
+ else
+ echo "failed: mismatched output"
+ diff $config_dir/$test.out $tmp_dir/$test.out
+ fail=$(($fail + 1))
+ fi
+ total=$(($total + 1))
+done
+
+for test in $tests; do
+ [[ $test =~ ^tst.*.cfg$ ]] || continue
+ reset
+ echo "$test ... \c"
+
+ cp $config_dir/$test $gate/.git/config || die "cp failed"
+ push > >(grep remote: >$tmp_dir/$test.out) 2>&1
+ err=$?
+
+ if [[ $err -ne 0 ]]; then
+ echo "failed: error code $err"
+ fail=$(($fail + 1))
+ cat $tmp_dir/$test.out
+ elif diff $config_dir/$test.out $tmp_dir/$test.out >/dev/null 2>&1; then
+ echo "passed."
+ pass=$(($pass + 1))
+ else
+ echo "failed: mismatched output"
+ diff $config_dir/$test.out $tmp_dir/$test.out
+ fail=$(($fail + 1))
+ fi
+
+ total=$(($total + 1))
+done
+
+echo
+echo "passed: $pass"
+echo "failed: $fail"
+echo "total: $total"
+
+if [[ $fail -ne 0 ]]; then
+ echo
+ echo $tmp_dir
+fi
+
+exit 0
Please sign in to comment.
Something went wrong with that request. Please try again.