Some recent tests accidentally depended on very new versions of git.
[gitweb.git] / git-subtree.sh
index cdf7b0992b4743ed4b848a3c19ce45cfe7d0c238..e76b45c2ddcdbd54b944aa72a774b45fa40cbfc3 100755 (executable)
@@ -16,7 +16,7 @@ git subtree split --prefix=<prefix> <commit...>
 h,help        show the help
 q             quiet
 d             show debug messages
-p,prefix=     the name of the subdir to split out
+P,prefix=     the name of the subdir to split out
 m,message=    use the given message as the commit message for the merge commit
  options for 'split'
 annotate=     add a prefix to commit message of new commits
@@ -78,7 +78,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 ;;
@@ -105,6 +105,14 @@ esac
 if [ -z "$prefix" ]; then
        die "You must provide the --prefix option."
 fi
+
+case "$command" in
+       add) [ -e "$prefix" ] && 
+               die "prefix '$prefix' already exists." ;;
+       *)   [ -e "$prefix" ] || 
+               die "'$prefix' does not exist; use 'git subtree add'" ;;
+esac
+
 dir="$(dirname "$prefix/.")"
 
 if [ "$command" != "pull" ]; then
@@ -166,9 +174,9 @@ rev_is_descendant_of_branch()
        newrev="$1"
        branch="$2"
        branch_hash=$(git rev-parse $branch)
-       match=$(git rev-list $newrev | grep $branch_hash)
+       match=$(git rev-list -1 $branch_hash ^$newrev)
 
-       if [ -n "$match" ]; then
+       if [ -z "$match" ]; then
                return 0
        else
                return 1
@@ -317,7 +325,7 @@ rejoin_msg()
                commit_message="Split '$dir/' into commit '$latest_new'"
        fi
        cat <<-EOF
-               $message
+               $commit_message
                
                git-subtree-dir: $dir
                git-subtree-mainline: $latest_old
@@ -520,8 +528,7 @@ cmd_split()
        eval "$grl" |
        while read rev parents; do
                revcount=$(($revcount + 1))
-               say -n "$revcount/$revmax ($createcount)
-"
+               say -n "$revcount/$revmax ($createcount)\r"
                debug "Processing commit: $rev"
                exists=$(cache_get $rev)
                if [ -n "$exists" ]; then
@@ -604,7 +611,11 @@ cmd_merge()
                rev="$new"
        fi
        
-       git merge -s subtree --message="$message" $rev
+       if [ -n "$message" ]; then
+               git merge -s subtree --message="$message" $rev
+       else
+               git merge -s subtree $rev
+       fi
 }
 
 cmd_pull()