Fix a minor problem in identifying squashes vs. normal splits.
[gitweb.git] / git-subtree.sh
index b7c741cfd43ef7501502f7be64174b0fd8385c7c..cccc3400fdd8e3a06ccf8ac8f17589ca08afbffb 100755 (executable)
@@ -102,7 +102,7 @@ esac
 if [ -z "$prefix" ]; then
        die "You must provide the --prefix option."
 fi
-dir="$prefix"
+dir="$(dirname "$prefix/.")"
 
 if [ "$command" != "pull" ]; then
        revs=$(git rev-parse $default --revs-only "$@") || exit $?
@@ -175,7 +175,7 @@ find_latest_squash()
        sq=
        main=
        sub=
-       git log --grep="^git-subtree-dir: $dir\$" \
+       git log --grep="^git-subtree-dir: $dir/*\$" \
                --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
        while read a b junk; do
                debug "$a $b $junk"
@@ -210,16 +210,18 @@ find_existing_splits()
        revs="$2"
        main=
        sub=
-       git log --grep="^git-subtree-dir: $dir\$" \
+       git log --grep="^git-subtree-dir: $dir/*\$" \
                --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
        while read a b junk; do
                case "$a" in
-                       START) main="$b"; sq="$b" ;;
+                       START) sq="$b" ;;
                        git-subtree-mainline:) main="$b" ;;
                        git-subtree-split:) sub="$b" ;;
                        END)
+                               debug "  Main is: '$main'"
                                if [ -z "$main" -a -n "$sub" ]; then
                                        # squash commits refer to a subtree
+                                       debug "  Squash: $sq from $sub"
                                        cache_set "$sq" "$sub"
                                fi
                                if [ -n "$main" -a -n "$sub" ]; then
@@ -322,6 +324,7 @@ subtree_for_commit()
        git ls-tree "$commit" -- "$dir" |
        while read mode type tree name; do
                assert [ "$name" = "$dir" ]
+               assert [ "$type" = "tree" ]
                echo $tree
                break
        done