develooper Front page | perl.perl5.porters | Postings from February 2013

Re: git-hook to prevent perlbug as patch author

From:
Tony Cook
Date:
February 27, 2013 13:20
Subject:
Re: git-hook to prevent perlbug as patch author
Message ID:
20130227132025.GA8374@mars.tony.develop-help.com
On Wed, Jan 30, 2013 at 07:38:29AM +0100, Steffen Mueller wrote:
> I will bribe Dennis into installing such post-receive a hook if
> somebody provides it.

An update hook as discussed is attached, with only the following
change:

--- update.orig 2013-01-28 11:04:13.000000000 +0100
+++ update      2013-02-27 13:22:35.000000000 +0100
@@ -78,6 +78,13 @@
                ;;
        refs/heads/*,commit)
                # branch
+               authoremail=`git log --format=%ae -n1 "$newrev"`
+               if [ "$refname" = refs/heads/blead ] && 
+                    ( git config --get-all blacklist.email | grep -qx "$authoremail" ) ;
+                   then
+                   echo "*** $authoremail cannot author new commits in blead" >&2
+                   exit 1
+               fi
                ;;
        refs/heads/*,delete)
                # delete branch

The blacklisted emails can be configured with git config:

  cd perl.git
  git config --add blacklist.email foo@example.com

Tested as follows:

  # make a new branch with some junk commit, using the default (good) author
  git checkout -b goodbranch blead
  Switched to a new branch 'goodbranch'
  echo g >>foo
  git add foo
  git commit -m "the new foo"
  [goodbranch 1956331] the new foo
   1 file changed, 1 insertion(+)
  # make a branch with the same change, authored by perlbug-followup@perl.org
  git checkout -b aepbfollowup goodbranch
  Switched to a new branch 'aepbfollowup'
  git commit --amend --author "Tony via perlbug <perlbug-followup@perl.org>" -m "pbf foo"
  [aepbfollowup d2cbbb2] pbf foo
   Author: Tony via perlbug <perlbug-followup@perl.org>
   1 file changed, 1 insertion(+)
  # make a branch with the same change, authored by perlbug@perl.org
  git checkout -b aeperlbug goodbranch
  Switched to a new branch 'aeperlbug'
  git commit --amend --author "Tony via perlbug <perlbug@perl.org>" -m "pb foo"
  [aeperlbug 20b64dc] pb foo
   Author: Tony via perlbug <perlbug@perl.org>
   1 file changed, 1 insertion(+)
  # test pushing a bad author to blead - this should fail
  git push updatetest aepbfollowup:blead
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects:  50% (1/2)   Compressing objects: 100% (2/2)   Compressing objects: 100% (2/2), done.
  Writing objects:  33% (1/3)   Writing objects:  66% (2/3)   Writing objects: 100% (3/3)   Writing objects: 100% (3/3), 294 bytes, done.
  Total 3 (delta 1), reused 0 (delta 0)
  remote: *** perlbug-followup@perl.org cannot author new commits in blead
  remote: error: hook declined to update refs/heads/blead
  To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
   ! [remote rejected] aepbfollowup -> blead (hook declined)
  error: failed to push some refs to 'tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git'
  # test pushing a bad author to another branch - this should succeed
  git push updatetest aepbfollowup
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects:  50% (1/2)   Compressing objects: 100% (2/2)   Compressing objects: 100% (2/2), done.
  Writing objects:  33% (1/3)   Writing objects:  66% (2/3)   Writing objects: 100% (3/3)   Writing objects: 100% (3/3), 294 bytes, done.
  Total 3 (delta 1), reused 0 (delta 0)
  To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
   * [new branch]      aepbfollowup -> aepbfollowup
  # test pushing the other bad author to blead - this should fail
  git push updatetest aeperlbug:blead
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects:  50% (1/2)   Compressing objects: 100% (2/2)   Compressing objects: 100% (2/2), done.
  Writing objects:  33% (1/3)   Writing objects:  66% (2/3)   Writing objects: 100% (3/3)   Writing objects: 100% (3/3), 284 bytes, done.
  Total 3 (delta 1), reused 0 (delta 0)
  remote: *** perlbug@perl.org cannot author new commits in blead
  remote: error: hook declined to update refs/heads/blead
  To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
   ! [remote rejected] aeperlbug -> blead (hook declined)
  error: failed to push some refs to 'tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git'
  # test pushing the other bad author to another branch - this should succeed
  git push updatetest aeperlbug
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects:  50% (1/2)   Compressing objects: 100% (2/2)   Compressing objects: 100% (2/2), done.
  Writing objects:  33% (1/3)   Writing objects:  66% (2/3)   Writing objects: 100% (3/3)   Writing objects: 100% (3/3), 284 bytes, done.
  Total 3 (delta 1), reused 0 (delta 0)
  To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
   * [new branch]      aeperlbug -> aeperlbug
  # test pushing the good author to blead - this should succeed
  git push updatetest goodbranch:blead
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects:  50% (1/2)   Compressing objects: 100% (2/2)   Compressing objects: 100% (2/2), done.
  Writing objects:  33% (1/3)   Writing objects:  66% (2/3)   Writing objects: 100% (3/3)   Writing objects: 100% (3/3), 265 bytes, done.
  Total 3 (delta 1), reused 0 (delta 0)
  To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
     185a72e..1956331  goodbranch -> blead
  # test pushing the good author to another branch - this should succeed
  git push updatetest goodbranch
  Total 0 (delta 0), reused 0 (delta 0)
  To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
   * [new branch]      goodbranch -> goodbranch

(edited to remove control characters)

Tony



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About