#!/bin/sh
-. /srv/git/hooks/server/update-no-rewind
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+/srv/git/hooks/server/update-no-rewind "$refname" "$oldrev" "$newrev" &&
+/srv/git/hooks/server/update-prefer-rebase "$refname" "$oldrev" "$newrev"
+++ /dev/null
-#!/bin/sh
-
-while read oldrev newrev refname ; do
- if expr "$oldrev" : '0*$' >/dev/null ; then
- exit 0
- fi
-
- # If they are introducing non-merge commits /and/ merge commits, it could
- # look like one of two ways. This way:
- #
- # * --- B --- * --- oldrev
- # \ \
- # new --- new --- newrev
- #
- # They basically had an un-shared local dev branch (probably by making a
- # merge) and instead should have done a rebase. Also, if they did:
- #
- # * --- B --- * --- oldrev
- # \ \
- # new --- new --- new -- newrev
- #
- # We should try and catch them--where the merge happened previously to
- # them doing more work in the newrev commit.
- #
- # But if it looks like:
- #
- # * --- B --- * --- oldrev
- # \ \
- # old --- new --- newrev
- #
- # Then they had a pre-shared branch that cannot be rebased and so they
- # were correct in doing a merge to tie "old" and "oldrev" together.
- #
- # Also, we obviously have to be okay with:
- #
- # * --- * --- * --- oldrev --- new --- new --- newrev
-
- git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $oldrev..$newrev | while read commit ; do
- number_of_parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | wc -l)
- if [[ $number_of_parents > 1 ]] ; then
- # Find the original branch point (B)
- parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit)
- baserev=$(git merge-base $parents)
-
- # For each parent
- git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | while read parent ; do
- all_commits=$(git rev-list $baserev..$parent | wc -l)
- new_commits=$(git rev-parse --not --branches | git rev-list --stdin $baserev..$parent | wc -l)
- if [[ $all_commits -eq $new_commits ]] ; then
- echo "----------------------------------------------------"
- echo
- echo "It looks like you should rebase instead of merging $commit"
- echo
- echo "----------------------------------------------------"
- exit 1
- fi
- done
- if [ $? -ne 0 ] ; then
- exit 1
- fi
- fi
- done
- if [ $? -ne 0 ] ; then
- exit 1
- fi
-done
-
--- /dev/null
+#!/bin/sh
+
+# Command line
+refname="$1"
+oldrev="$2"
+newrev="$3"
+
+if expr "$oldrev" : '0*$' >/dev/null ; then
+ exit 0
+fi
+
+git rev-parse --not --branches | git rev-list --stdin $oldrev..$newrev | while read commit ; do
+ number_of_parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | wc -l)
+ if [[ $number_of_parents > 1 ]] ; then
+ # Find the original branch point (B)
+ parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit)
+ baserev=$(git merge-base $parents)
+
+ # For each parent
+ git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | while read parent ; do
+ all_commits=$(git rev-list $baserev..$parent | wc -l)
+ new_commits=$(git rev-parse --not --branches | git rev-list --stdin $baserev..$parent | wc -l)
+ if [[ $all_commits -eq $new_commits ]] ; then
+ echo "----------------------------------------------------"
+ echo
+ echo "It looks like you should rebase instead of merging $commit"
+ echo
+ echo "----------------------------------------------------"
+ exit 1
+ fi
+ done
+ if [ $? -ne 0 ] ; then
+ exit 1
+ fi
+ fi
+done
+
+++ /dev/null
-#!/bin/sh
-
-test_description='server pre-receive prefer rebase'
-
-. ./test-lib.sh
-
-test_expect_success 'setup' '
- echo "setup" >a &&
- git add a &&
- git commit -m "setup" &&
- 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 &&
- git fetch
-'
-
-install_server_hook 'pre-receive-prefer-rebase' 'pre-receive'
-
-test_expect_success 'all local changes do not need a merge' '
- # server is on "setup"
-
- # make an outstanding change for us--but do not push
- echo "$test_name" >a.client1 &&
- git add a.client1 &&
- git commit -m "$test_name on client1" &&
-
- # have another client commit (in this case, it is the server, but close enough)
- cd server &&
- echo "$test_name" >a.client2 &&
- git add a.client2 &&
- git commit -m "$test_name on client2" &&
-
- # go back to our client and it will merge in our changes
- cd .. &&
- git pull &&
- merge=$(git rev-parse HEAD) &&
-
- ! git push 2>push.err &&
- cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
- git reset --hard origin/master
-'
-
-test_expect_success 'all local changes do not need a merge even with more commits after' '
- # server is on "setup"
-
- # make an outstanding change for us--but do not push
- echo "$test_name" >a.client1 &&
- git add a.client1 &&
- git commit -m "$test_name on client1" &&
-
- # have another client commit (in this case, it is the server, but close enough)
- cd server &&
- echo "$test_name" >a.client2 &&
- git add a.client2 &&
- git commit -m "$test_name on client2" &&
-
- # go back to our client and it will merge in our changes
- cd .. &&
- git pull &&
- merge=$(git rev-parse HEAD) &&
-
- # To complicate things, have them add another change
- echo "$test_name again" >a.client1 &&
- git commit -a -m "$test_name on client1 again" &&
-
- ! git push 2>push.err &&
- cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
- git reset --hard origin/master
-'
-
-test_expect_success 'already shared topic changes do warrant a merge' '
- # server is on "setup"
-
- # make a change on topic for us and share it
- git checkout -b topic master &&
- echo "$test_name" >a.client1 &&
- git add a.client1 &&
- git commit -m "$test_name on client1 and topic" &&
- git push origin topic &&
-
- # make an outstanding change that we will have to merge later
- echo "$test_name again" >>a.client1 &&
- git commit -a -m "$test_name on client1 and topic again" &&
-
- # have another client commit to master (in this case, it is the server, but close enough)
- cd server &&
- echo "$test_name" >a.client2 &&
- git add a.client2 &&
- git commit -m "$test_name on client2" &&
-
- # go back to our client and it will merge in our changes
- cd .. &&
- git checkout master &&
- git pull &&
- git merge topic &&
-
- git push
-'
-
-test_expect_success 'simple commit' '
- # go back to topic and make a simple commit/push as a sanity check
- git checkout topic &&
- echo "$test_name" >>a.client1 &&
- git commit -a -m "$test_name on client1 and topic" &&
- git push
-'
-
-test_done
-
--- /dev/null
+#!/bin/sh
+
+test_description='server update prefer rebase'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo "setup" >a &&
+ git add a &&
+ git commit -m "setup" &&
+ 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 &&
+ git fetch
+'
+
+install_server_hook 'update-prefer-rebase' 'update'
+
+test_expect_success 'all local changes do not need a merge' '
+ # server is on "setup"
+
+ # make an outstanding change for us--but do not push
+ echo "$test_name" >a.client1 &&
+ git add a.client1 &&
+ git commit -m "$test_name on client1" &&
+
+ # have another client commit (in this case, it is the server, but close enough)
+ cd server &&
+ echo "$test_name" >a.client2 &&
+ git add a.client2 &&
+ git commit -m "$test_name on client2" &&
+
+ # go back to our client and it will merge in our changes
+ cd .. &&
+ git pull &&
+ merge=$(git rev-parse HEAD) &&
+
+ ! git push 2>push.err &&
+ cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
+ git reset --hard origin/master
+'
+
+test_expect_success 'all local changes do not need a merge even with more commits after' '
+ # server is on "setup"
+
+ # make an outstanding change for us--but do not push
+ echo "$test_name" >a.client1 &&
+ git add a.client1 &&
+ git commit -m "$test_name on client1" &&
+
+ # have another client commit (in this case, it is the server, but close enough)
+ cd server &&
+ echo "$test_name" >a.client2 &&
+ git add a.client2 &&
+ git commit -m "$test_name on client2" &&
+
+ # go back to our client and it will merge in our changes
+ cd .. &&
+ git pull &&
+ merge=$(git rev-parse HEAD) &&
+
+ # To complicate things, have them add another change
+ echo "$test_name again" >a.client1 &&
+ git commit -a -m "$test_name on client1 again" &&
+
+ ! git push 2>push.err &&
+ cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
+ git reset --hard origin/master
+'
+
+test_expect_success 'already shared topic changes do warrant a merge' '
+ # server is on "setup"
+
+ # make a change on topic for us and share it
+ git checkout -b topic master &&
+ echo "$test_name" >a.client1 &&
+ git add a.client1 &&
+ git commit -m "$test_name on client1 and topic" &&
+ git push origin topic &&
+
+ # make an outstanding change that we will have to merge later
+ echo "$test_name again" >>a.client1 &&
+ git commit -a -m "$test_name on client1 and topic again" &&
+
+ # have another client commit to master (in this case, it is the server, but close enough)
+ cd server &&
+ echo "$test_name" >a.client2 &&
+ git add a.client2 &&
+ git commit -m "$test_name on client2" &&
+
+ # go back to our client and it will merge in our changes
+ cd .. &&
+ git checkout master &&
+ git pull &&
+ git merge topic &&
+
+ git push
+'
+
+test_expect_success 'simple commit' '
+ # go back to topic and make a simple commit/push as a sanity check
+ git checkout topic &&
+ echo "$test_name" >>a.client1 &&
+ git commit -a -m "$test_name on client1 and topic" &&
+ git push
+'
+
+test_done
+