Sync with Git 2.6.6
[gitweb.git] / contrib / subtree / git-subtree.sh
index 308b777b0aa43a7466fb3402cc67c1f023f57a7a..5c8372709b31b4ecd8caf0e05faedd0626f03021 100755 (executable)
@@ -90,7 +90,7 @@ while [ $# -gt 0 ]; do
                --annotate) annotate="$1"; shift ;;
                --no-annotate) annotate= ;;
                -b) branch="$1"; shift ;;
-               -P) prefix="$1"; shift ;;
+               -P) prefix="${1%/}"; shift ;;
                -m) message="$1"; shift ;;
                --no-prefix) prefix= ;;
                --onto) onto="$1"; shift ;;
@@ -479,8 +479,16 @@ copy_or_skip()
                        p="$p -p $parent"
                fi
        done
-       
-       if [ -n "$identical" ]; then
+
+       copycommit=
+       if [ -n "$identical" ] && [ -n "$nonidentical" ]; then
+               extras=$(git rev-list --count $identical..$nonidentical)
+               if [ "$extras" -ne 0 ]; then
+                       # we need to preserve history along the other branch
+                       copycommit=1
+               fi
+       fi
+       if [ -n "$identical" ] && [ -z "$copycommit" ]; then
                echo $identical
        else
                copy_commit $rev $tree "$p" || exit $?