]> git.droids-corp.org - git-central.git/commitdiff
Server side (non-trac) commit message enforcement.
authorStephen Haberman <stephen@exigencecorp.com>
Fri, 20 Jun 2008 01:21:29 +0000 (20:21 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Fri, 20 Jun 2008 01:21:29 +0000 (20:21 -0500)
client/commit-msg
server/post-receive-trac
server/pre-receive-ticket [new file with mode: 0644]
tests/t1000-commit-msg-ticket-hook.sh
tests/t2000-server-pre-receive-ticket.sh [new file with mode: 0644]
tests/test-lib.sh

index 60f638e0f80513dc82ae50b9700b647999ea7efa..0800f02131d7ee9d33b753c23473219cfc255c3f 100644 (file)
@@ -4,7 +4,7 @@ grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' "$1" > /dev/null
 
 if [ $? -ne 0 ]
 then
-    echo "Please reference a ticket"
-    exit 1
+       echo "Please reference a ticket"
+       exit 1
 fi
 
index fc8d0e10b1543f148b69d95b19b4d4cb6757a645..ab9362c3e9d3f7b2dc78a391bc7200b93dc9215b 100644 (file)
@@ -9,8 +9,8 @@ while read oldrev newrev refname ; do
                git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $newrev
        else
                git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $oldrev..$newrev
-       fi | while read com ; do
-               /home/BIPFS/shaberman/local/bin/python /srv/git/hooks/trac-post-commit-hook.py -p "$TRAC_ENV" -r "$com"
+       fi | while read commit ; do
+               /home/BIPFS/shaberman/local/bin/python /srv/git/hooks/trac-post-commit-hook.py -p "$TRAC_ENV" -r "$commit"
        done
 done
 
diff --git a/server/pre-receive-ticket b/server/pre-receive-ticket
new file mode 100644 (file)
index 0000000..7858585
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+while read oldrev newrev refname ; do
+       if expr "$oldrev" : '0*$' >/dev/null
+       then
+               git rev-list $newrev
+       else
+               git rev-list $oldrev..$newrev
+       fi | while read commit ; do
+               git log -n 1 '--pretty=format:%s%n%b' "$commit" | grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' > /dev/null
+               if [ $? -ne 0 ]
+               then
+                       echo "Commit $commit does not reference a ticket"
+                       exit 1
+               fi
+       done
+done
+
index 033f08a94b2049273c5f7d84e509d435d82fb338..6a0b59163a4cf36375627f9fd7f4780becd78150 100644 (file)
@@ -1,10 +1,9 @@
 #!/bin/sh
 
-test_description='commit-msg ticket hook'
+test_description='client commit-msg ticket enforcer'
 
 . ./test-lib.sh
 
-
 # setup the commit-msg hook
 install_client_hook 'commit-msg' 'commit-msg'
 
diff --git a/tests/t2000-server-pre-receive-ticket.sh b/tests/t2000-server-pre-receive-ticket.sh
new file mode 100644 (file)
index 0000000..b84dca5
--- /dev/null
@@ -0,0 +1,46 @@
+
+#!/bin/sh
+
+test_description='server pre-receive ticket enforcer'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       echo This is a test. >a &&
+       git add a &&
+       git commit -m "a" &&
+       git clone ./. server &&
+       rm -fr server/.git/hooks &&
+       git remote add origin ./server &&
+       git config --add branch.master.remote origin &&
+       git config --add branch.master.merge refs/heads/master
+'
+
+# setup the pre-receive hook
+install_server_hook 'pre-receive-ticket' 'pre-receive'
+
+test_expect_success 'reject with bad message' '
+       echo $test_name >a &&
+       git commit -a -m "foo" &&
+       git push >push.out 2>push.err
+       head=$(git rev-parse HEAD)
+       cat push.err | grep "Commit $head does not reference a ticket"
+'
+
+# the last test has a dirty commit message, so ammend it with a good message
+test_expect_success 'accept with re' '
+       echo $test_name >a &&
+       git commit --amend -m "foo re #3222" &&
+       git push
+'
+
+test_expect_success 'accept with re on second line' '
+       echo $test_name >a &&
+       echo "first subject line" >msg
+       echo "second line re #322" >>msg
+       git commit -a -F msg &&
+       git push
+'
+
+test_done
+
index 1db8ebd7d0b3e943b14ea9ee5e76dc6b2de86d05..feb64c64d45e32710a0b2016fd687c1e4cc01b0c 100644 (file)
@@ -435,3 +435,9 @@ install_client_hook () {
     chmod +x "$TRASH_HOOKS/$2"
 }
 
+install_server_hook () {
+    mkdir -p "server/.git/hooks"
+    cp "../../server/$1" "server/.git/hooks/$2"
+    chmod +x "server/.git/hooks/$2"
+}
+