From 098651f67bd70d98d76cd8457600934a9bcaefa1 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Tue, 14 Oct 2008 22:40:03 -0500 Subject: [PATCH] It's unlikely, but warn the user to update first before telling them they need to merge. --- server/update-ensure-follows | 9 ++++++++- tests/t2700-server-ensure-follows.sh | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/server/update-ensure-follows b/server/update-ensure-follows index 2cf6338..a3c6b92 100644 --- a/server/update-ensure-follows +++ b/server/update-ensure-follows @@ -50,7 +50,14 @@ for ((i = 0 ; i < count ; i++)) do if [ $? -eq 0 ] ; then missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l) if [ $missing_commits -ne 0 ] ; then - display_error_message "You need to merge $follow into $short_refname" + # If for some reason people are stupid and push with a --force flag, + # we should warn them to update first in case one of their teammates + # already merged for them + if [ "$(git merge-base $oldrev $newrev)" != "$oldrev" ] ; then + display_error_message "You need to update your local branch $short_refname" + else + display_error_message "You need to merge $follow into $short_refname" + fi exit 1 fi fi diff --git a/tests/t2700-server-ensure-follows.sh b/tests/t2700-server-ensure-follows.sh index a5eb1fa..0f9b8f9 100644 --- a/tests/t2700-server-ensure-follows.sh +++ b/tests/t2700-server-ensure-follows.sh @@ -11,8 +11,6 @@ test_expect_success '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 ' @@ -51,6 +49,29 @@ test_expect_success 'branch with moved stable requires merge' ' git push origin topic1 ' +test_expect_success 'branch with moved stable is told to update first' ' + git checkout stable && + echo "$test_name" >a && + git commit -a -m "Change on stable" && + git push origin stable && + + # Someone fixes stable first + cd server && + git checkout -f topic1 && + git merge stable && + cd .. && + + git checkout topic1 && + echo "$test_name" >a.topic1 && + git commit -a -m "Change on topic1." && + ! git push --force origin topic1 2>push.err && + cat push.err | grep "You need to update your local branch topic1" && + + # Now it will work as the teammate merged for us + git pull origin topic1 && + git push origin topic1 +' + test_expect_success 'branch with moved stable as second branch requires merge' ' cd server && git config hooks.update-ensure-follows.branches "foo stable" && -- 2.20.1