Typo when searching for existing splits.
[gitweb.git] / git-subtree.sh
index f2a1c6aae4561fa7d85a4a7faabe4ea8771d74b1..8b797dfc23c8cfe7c5f7f4dea877be0dda45c87e 100755 (executable)
@@ -17,6 +17,7 @@ h,help        show the help
 q             quiet
 prefix=       the name of the subdir to split out
  options for 'split'
+annotate=     add a prefix to commit message of new commits
 onto=         try connecting new tree to an existing one
 rejoin        merge the new branch back into HEAD
 ignore-joins  ignore prior --rejoin commits
@@ -30,6 +31,7 @@ command=
 onto=
 rejoin=
 ignore_joins=
+annotate=
 
 debug()
 {
@@ -55,6 +57,8 @@ while [ $# -gt 0 ]; do
        shift
        case "$opt" in
                -q) quiet=1 ;;
+               --annotate) annotate="$1"; shift ;;
+               --no-annotate) annotate= ;;
                --prefix) prefix="$1"; shift ;;
                --no-prefix) prefix= ;;
                --onto) onto="$1"; shift ;;
@@ -125,13 +129,23 @@ cache_set()
        echo "$newrev" >"$cachedir/$oldrev"
 }
 
+# if a commit doesn't have a parent, this might not work.  But we only want
+# to remove the parent from the rev-list, and since it doesn't exist, it won't
+# be there anyway, so do nothing in that case.
+try_remove_previous()
+{
+       if git rev-parse "$1^" >/dev/null 2>&1; then
+               echo "^$1^"
+       fi
+}
+
 find_existing_splits()
 {
        debug "Looking for prior splits..."
        dir="$1"
        revs="$2"
        git log --grep="^git-subtree-dir: $dir\$" \
-               --pretty=format:'%s%n%n%b%nEND' "$revs" |
+               --pretty=format:'%s%n%n%b%nEND' $revs |
        while read a b junk; do
                case "$a" in
                        git-subtree-mainline:) main="$b" ;;
@@ -140,7 +154,8 @@ find_existing_splits()
                                if [ -n "$main" -a -n "$sub" ]; then
                                        debug "  Prior: $main -> $sub"
                                        cache_set $main $sub
-                                       echo "^$main^ ^$sub^"
+                                       try_remove_previous "$main"
+                                       try_remove_previous "$sub"
                                        main=
                                        sub=
                                fi
@@ -167,7 +182,7 @@ copy_commit()
                        GIT_COMMITTER_NAME \
                        GIT_COMMITTER_EMAIL \
                        GIT_COMMITTER_DATE
-               (echo -n '*'; cat ) |  # FIXME
+               (echo -n "$annotate"; cat ) |
                git commit-tree "$2" $3  # reads the rest of stdin
        ) || die "Can't copy commit $1"
 }