X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-submodule.sh;h=efc86ad4e0b90edbbf5a927aa87e7ad4b1a1949e;hb=refs%2Fheads%2Fmaster;hp=2a93c611ea64e4c1f4f6cfa0d2dfc21d96d1a421;hpb=ea115a0d43d176f873855f9a7372376161dd8e65;p=git.git diff --git a/git-submodule.sh b/git-submodule.sh index 2a93c611e..efc86ad4e 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -132,30 +132,11 @@ module_clone() gitdir_base= name=$(module_name "$path" 2>/dev/null) test -n "$name" || name="$path" - base_path=$(dirname "$path") + base_name=$(dirname "$name") gitdir=$(git rev-parse --git-dir) - gitdir_base="$gitdir/modules/$base_path" - gitdir="$gitdir/modules/$path" - - case $gitdir in - /*) - a="$(cd_to_toplevel && pwd)/" - b=$gitdir - while [ "$b" ] && [ "${a%%/*}" = "${b%%/*}" ] - do - a=${a#*/} b=${b#*/}; - done - - rel="$a$name" - rel=`echo $rel | sed -e 's|[^/]*|..|g'` - rel_gitdir="$rel/$b" - ;; - *) - rel=`echo $name | sed -e 's|[^/]*|..|g'` - rel_gitdir="$rel/$gitdir" - ;; - esac + gitdir_base="$gitdir/modules/$base_name" + gitdir="$gitdir/modules/$name" if test -d "$gitdir" then @@ -168,7 +149,29 @@ module_clone() die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")" fi - echo "gitdir: $rel_gitdir" >"$path/.git" + a=$(cd "$gitdir" && pwd)/ + b=$(cd "$path" && pwd)/ + # normalize Windows-style absolute paths to POSIX-style absolute paths + case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac + case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac + # Remove all common leading directories after a sanity check + if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then + die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")" + fi + while test "${a%%/*}" = "${b%%/*}" + do + a=${a#*/} + b=${b#*/} + done + # Now chop off the trailing '/'s that were added in the beginning + a=${a%/} + b=${b%/} + + rel=$(echo $b | sed -e 's|[^/]*|..|g') + echo "gitdir: $rel/$a" >"$path/.git" + + rel=$(echo $a | sed -e 's|[^/]*|..|g') + (clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b") } #