Don't let in tags that are not within a branch.
[git-central.git] / server / update-prefer-rebase
index 5d9948a..0c9126a 100644 (file)
@@ -32,7 +32,6 @@
 #
 # * --- * --- * --- oldrev --- new --- new --- newrev
 
-# Command line
 refname="$1"
 oldrev="$2"
 newrev="$3"
@@ -45,20 +44,30 @@ 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
+               # Hack to not interfer with the update-stable "--no-ff" method
+               if [[ "$refname" == "refs/heads/stable" && "$commit" == "$newrev" ]] ; then
+                       exit 0
+               fi
+
                # 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 "----------------------------------------------------"
+               # For each baserev
+               git merge-base --all $parents | while read baserev ; do
+                       # 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 --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 "----------------------------------------------------"
+                                       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
                done