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

Allowing forced updates to branches

Thread Next
From:
Tony Cook
Date:
January 28, 2013 10:40
Subject:
Allowing forced updates to branches
Message ID:
20130128104012.GD10179@mars.tony.develop-help.com
Currently we dis-allow all forced updates to branches on
perl5.git.perl.org/perl.git, which has led to some complaints.

The following change to hooks/update:

--- bareperl.git/hooks/update.orig      2013-01-28 11:04:13.000000000 +0100
+++ bareperl.git/hooks/update   2013-01-28 11:11:29.000000000 +0100
@@ -78,6 +78,14 @@
                ;;
        refs/heads/*,commit)
                # branch
+               merge_branch=''
+               if [ "$oldrev" != "0000000000000000000000000000000000000000" ] ; then
+                       merge_base=`git merge-base $oldrev $newrev`
+               fi
+               if [ "$merge_base" != "$oldrev" -a "`perl -e'$ARGV[0] !~ m!^refs/heads/(?:blead|maint|perl)! and print qq(ok)' $refname`" != "ok" ]; then
+                       echo "*** It is forbidden to push non-fast-forward commits to blead/maint branches in this repository" >&2
+                       exit 1
+               fi
                ;;
        refs/heads/*,delete)
                # delete branch

appears to allow forced updates to our non-protected branches.

Tested as follows:

# updatetest is a bare perl repo with hooks/update replaced
# receive.denynonfastforwards is not configured
# make some test commits - a fast forward
git checkout -b ffbranch updatetest/blead
Switched to a new branch 'ffbranch'
Branch ffbranch set up to track remote branch blead from updatetest.
touch foo.txt ; git add foo.txt ; git commit -m 'ff commit'
[ffbranch 1c35d5b] ff commit
 0 files changed
 create mode 100644 foo.txt
# a non-fast forward
git checkout -b nonffbranch updatetest/blead
Switched to a new branch 'nonffbranch'
Branch nonffbranch set up to track remote branch blead from updatetest.
git reset --hard HEAD^
HEAD is now at d907e2e Belated Happy New Year!
touch foo.txt ; git add foo.txt ; git commit -m 'non-ff commit'
[nonffbranch f7a993b] non-ff commit
 0 files changed
 create mode 100644 foo.txt
# test the hook
# push a new branch (this produced an alarming message originally)
git push updatetest ffbranch:testbranch
To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
 * [new branch]      ffbranch -> testbranch
# this should fail to push
git push updatetest nonffbranch:testbranch
To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
 ! [rejected]        nonffbranch -> testbranch (non-fast-forward)
error: failed to push some refs to 'tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
# success as a forced update
git push updatetest +nonffbranch:testbranch
To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
 + 1c35d5b...f7a993b nonffbranch -> testbranch (forced update)
# should fail to push
git push updatetest nonffbranch:blead
To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
 ! [rejected]        nonffbranch -> blead (non-fast-forward)
error: failed to push some refs to 'tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
# should fail to push
git push updatetest +nonffbranch:blead
remote: *** It is forbidden to push non-fast-forward commits to blead/maint branches in this repository
remote: error: hook declined to update refs/heads/blead
To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
 ! [remote rejected] nonffbranch -> blead (hook declined)
error: failed to push some refs to 'tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git'
# should fail to push
git push updatetest +nonffbranch:maint-5.16
remote: *** It is forbidden to push non-fast-forward commits to blead/maint branches in this repository
remote: error: hook declined to update refs/heads/maint-5.16
To tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git
 ! [remote rejected] nonffbranch -> maint-5.16 (hook declined)
error: failed to push some refs to 'tonyc@users.perl5.git.perl.org:/home/tonyc/bareperl.git'

Please review as a possible update to perl.git's update hook.

Thanks,
Tony

Thread Next


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