git-hooks/commit-msg | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-)
New commits: commit 31dca4d87f51045d2b0568b4020a4d549375b215 Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Mon May 14 02:37:52 2012 -0500 fix issue with repeated I in case of amend commit Change-Id: I2f0f02fb545ae6d63f2d4e46327f6ee402ab608c Signed-off-by: Petr Mladek <pmla...@suse.cz> diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index d784d65..ad6400d 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -100,7 +100,7 @@ add_ChangeId() { return fi - id=`grep -i '^Change-Id:' "$MSG" | sed -e "s/.*://"` + id=`grep -i '^Change-Id:' "$MSG" | sed -e "s/.*: I//"` temp_msg=`grep -v -i '^Change-Id:' "$MSG"` echo "$temp_msg" > "$MSG" commit dbae2cbc29f960916469f33a9dd153157a42c64a Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Thu May 3 03:17:35 2012 -0500 commit-hook: tweak add_ChangeId() to tolerate git-am -s behavior git-am -s add systematically an empty line before adding the signoff line, which interfere with gerrit's rule that the ChangeID must be in the last paragraph This patch address that be remoming an existing Change-Id from the commit message and re-insterting it at the 'proper' place Change-Id: I I742b17031c6e3da4f9d94dcb0579bce8c496d41d Signed-off-by: Norbert Thiebaud <nthieb...@gmail.com> Signed-off-by: Petr Mladek <pmla...@suse.cz> diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index f8df4e2..d784d65 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -100,12 +100,14 @@ add_ChangeId() { return fi - if grep -i '^Change-Id:' "$MSG" >/dev/null + id=`grep -i '^Change-Id:' "$MSG" | sed -e "s/.*://"` + temp_msg=`grep -v -i '^Change-Id:' "$MSG"` + echo "$temp_msg" > "$MSG" + + if test -z "$id" then - return + id=`_gen_ChangeId` fi - - id=`_gen_ChangeId` perl -e ' $MSG = shift; $id = shift; commit e9f8b89ea8781f115c8782296d61f833fc1c8f7b Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Thu Apr 26 17:25:52 2012 -0500 add gerrit ChangeId generation to commit-msg git hook Change-Id: I30c370f0479743a831be29a0fa7cb447c7119ee4 Signed-off-by: Petr Mladek <pmla...@suse.cz> diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index f2bcb3f..f8df4e2 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -15,6 +15,7 @@ # This example catches duplicate Signed-off-by lines. base_dir=$(dirname $0) +MSG="$1" abort() { cp $1 $1.save @@ -61,8 +62,110 @@ if [ -n "`sed '/^#/,$d' $1 | grep '^[[:space:]]\+\*.*:'`" -a -z "`grep '^\*' $1` abort "$1" "Please don't use whitespace in front of '* file: Description.' entries." fi -if [ -f "${base_dir}/gerrit-commit-msg" ] ; then - source "${base_dir}/gerrit-commit-msg" -fi +#------------------ copied gerrit commit-msg hook to handle ChangeId --> +# From Gerrit Code Review 2.3 +# +# Part of Gerrit Code Review (http://code.google.com/p/gerrit/) +# +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +CHANGE_ID_AFTER="Bug|Issue" + +# Check for, and add if missing, a unique Change-Id +# +add_ChangeId() { + clean_message=`sed -e ' + /^diff --git a\/.*/{ + s/// + q + } + /^Signed-off-by:/d + /^#/d + ' "$MSG" | git stripspace` + if test -z "$clean_message" + then + return + fi + + if grep -i '^Change-Id:' "$MSG" >/dev/null + then + return + fi + + id=`_gen_ChangeId` + perl -e ' + $MSG = shift; + $id = shift; + $CHANGE_ID_AFTER = shift; + + undef $/; + open(I, $MSG); $_ = <I>; close I; + s|^diff --git a/.*||ms; + s|^#.*$||mg; + exit unless $_; + + @message = split /\n/; + $haveFooter = 0; + $startFooter = @message; + for($line = @message - 1; $line >= 0; $line--) { + $_ = $message[$line]; + + if (/^[a-zA-Z0-9-]+:/ && !m,^[a-z0-9-]+://,) { + $haveFooter++; + next; + } + next if /^[ []/; + $startFooter = $line if ($haveFooter && /^\r?$/); + last; + } + + @footer = @message[$startFooter+1..@message]; + @message = @message[0..$startFooter]; + push(@footer, "") unless @footer; + + for ($line = 0; $line < @footer; $line++) { + $_ = $footer[$line]; + next if /^($CHANGE_ID_AFTER):/i; + last; + } + splice(@footer, $line, 0, "Change-Id: I$id"); + + $_ = join("\n", @message, @footer); + open(O, ">$MSG"); print O; close O; + ' "$MSG" "$id" "$CHANGE_ID_AFTER" +} +_gen_ChangeIdInput() { + echo "tree `git write-tree`" + if parent=`git rev-parse HEAD^0 2>/dev/null` + then + echo "parent $parent" + fi + echo "author `git var GIT_AUTHOR_IDENT`" + echo "committer `git var GIT_COMMITTER_IDENT`" + echo + printf '%s' "$clean_message" +} +_gen_ChangeId() { + _gen_ChangeIdInput | + git hash-object -t commit --stdin +} + + +add_ChangeId +#------------------ copied gerrit commit-msg hook to handle ChangeId <-- + exit 0 commit 1e262c9ffd3d3ff83b0d94f048f6b4653899340c Author: Miklos Vajna <vmik...@suse.cz> Date: Sat Mar 24 18:01:34 2012 +0100 git-hooks: commit-msg should not search for whitespace in the diff itself The additional sed removes every line after seeing the first line starting with a #, just like git will do it later as well. See: http://article.gmane.org/gmane.comp.documentfoundation.libreoffice.devel/26794 Signed-off-by: Petr Mladek <pmla...@suse.cz> diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index 378acfa..f2bcb3f 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -57,7 +57,7 @@ fi # Check for whitespace in front of *'s -if [ -n "`grep '^[[:space:]]\+\*.*:' $1`" -a -z "`grep '^\*' $1`" ] ; then +if [ -n "`sed '/^#/,$d' $1 | grep '^[[:space:]]\+\*.*:'`" -a -z "`grep '^\*' $1`" ] ; then abort "$1" "Please don't use whitespace in front of '* file: Description.' entries." fi commit 4efc0b81cba20de5b4420c0dcebdbb85b98e3686 Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Tue Mar 6 04:12:01 2012 -0600 call the gerrit commit-msg hook if present This a a prep-work for if and when we use gerrit it is very important to call gerrit's commit-msg hook and the sooner we teach our own hook to play nice with it the less likely we will have issue during migration Signed-off-by: Petr Mladek <pmla...@suse.cz> diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index 6257213..378acfa 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -14,6 +14,8 @@ # This example catches duplicate Signed-off-by lines. +base_dir=$(dirname $0) + abort() { cp $1 $1.save cat >&2 <<EOF @@ -59,4 +61,8 @@ if [ -n "`grep '^[[:space:]]\+\*.*:' $1`" -a -z "`grep '^\*' $1`" ] ; then abort "$1" "Please don't use whitespace in front of '* file: Description.' entries." fi +if [ -f "${base_dir}/gerrit-commit-msg" ] ; then + source "${base_dir}/gerrit-commit-msg" +fi + exit 0 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits