New branches should not get the update your local branch message.
[git-central.git] / server / update-ensure-follows
index 2d5ef08..65fb021 100644 (file)
@@ -9,6 +9,8 @@
 # in it.
 #
 
+. $(dirname $0)/functions
+
 # Command line
 refname="$1"
 oldrev="$2"
@@ -44,15 +46,18 @@ follows=($follows)
 count=${#follows[@]}
 for ((i = 0 ; i < count ; i++)) do
        follow="${follows[$i]}"
-       git rev-parse "$follow"
+       git rev-parse --verify --quiet "$follow"
        if [ $? -eq 0 ] ; then
                missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l)
                if [ $missing_commits -ne 0 ] ; then
-                       echo "----------------------------------------------------"
-                       echo
-                       echo "You need to merge $follow into $short_refname"
-                       echo
-                       echo "----------------------------------------------------"
+                       # 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 [ "0000000000000000000000000000000000000000" != "$oldrev" -a "$(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