From 423f5265f3ede96f4640b0c4f2048acc838e8401 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Wed, 23 Jul 2008 17:36:09 -0500 Subject: [PATCH] Don't let merge commits fool the prefer-rebase script. --- server/update-prefer-rebase | 3 +- ...ver-update-prefer-rebase-even-if-merges.sh | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/t2301-server-update-prefer-rebase-even-if-merges.sh diff --git a/server/update-prefer-rebase b/server/update-prefer-rebase index 7dc1ef8..79c3bef 100644 --- a/server/update-prefer-rebase +++ b/server/update-prefer-rebase @@ -56,7 +56,8 @@ git rev-parse --not --branches | git rev-list --stdin $oldrev..$newrev | while r # 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) + echo "looking at $baserev..$parent for $commit" + all_commits=$(git rev-list --first-parent $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 "----------------------------------------------------" diff --git a/tests/t2301-server-update-prefer-rebase-even-if-merges.sh b/tests/t2301-server-update-prefer-rebase-even-if-merges.sh new file mode 100644 index 0000000..1f3cb20 --- /dev/null +++ b/tests/t2301-server-update-prefer-rebase-even-if-merges.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +test_description='server update prefer rebase (with incoming merges)' + +. ./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 && + + # Specifically, setup a stable that we will merge and check for rebase + git checkout -b stable master && + echo "setup.stable" >a && + git commit -a -m "stable" && + git push origin stable +' + +install_server_hook 'update-prefer-rebase' 'update' + +test_expect_success 'merging in stable does not fool the script' ' + # start our branch, and share it + git checkout -b topic1 stable && + git config --add branch.topic1.remote origin && + git config --add branch.topic1.merge refs/heads/topic1 && + echo "topic1" >a.topic1 && + git add a.topic1 && + git commit -m "topic1" && + git push origin topic1 && + + # now, separately, move ahead stable, and share it + git checkout stable + echo "setup.stable.moved" >a && + git commit -a -m "stable moved" && + git push origin stable && + + # have another client commit (in this case, it is the server, but close enough) move topic1 + cd server && + git checkout topic1 && + echo "$test_name" >a.client2 && + git add a.client2 && + git commit -m "topic1 changed by client2" && + cd .. && + + # now locally try and merge in stable (even though we are out of date) + git checkout topic1 && + git merge stable && + + # We are shutdown for being a rewind + ! git push 2>push.err && + cat push.err | grep "[rejected] topic1 -> topic1 (non-fast forward)" + + # Make a new merge commit + git pull && + ! git push 2>push.err && + cat push.err | grep "It looks like you should rebase instead of merging" +' + +test_done + -- 2.39.5