X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-submodule.sh;h=c405caaa0ee6998c4bdd39f97c7d53edcdcbea48;hb=d75219b4a8a9c44520ddca234cde992498383b89;hp=928a62f626fe7ff1db8239713d94ff9aa25158eb;hpb=2ef89f38568c9bfa663a8c79354e6d2135fb6bf3;p=git.git diff --git a/git-submodule.sh b/git-submodule.sh index 928a62f62..c405caaa0 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -104,9 +104,9 @@ module_name() re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g') name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' | sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' ) - test -z "$name" && - die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$path'")" - echo "$name" + test -z "$name" && + die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$path'")" + echo "$name" } # @@ -130,7 +130,8 @@ module_clone() gitdir= gitdir_base= - name=$(module_name "$path") + name=$(module_name "$path" 2>/dev/null) + test -n "$name" || name="$path" base_path=$(dirname "$path") gitdir=$(git rev-parse --git-dir) @@ -159,18 +160,33 @@ module_clone() if test -d "$gitdir" then mkdir -p "$path" - echo "gitdir: $rel_gitdir" >"$path/.git" rm -f "$gitdir/index" else mkdir -p "$gitdir_base" - if test -n "$reference" - then - git-clone $quiet "$reference" -n "$url" "$path" --separate-git-dir "$gitdir" - else - git-clone $quiet -n "$url" "$path" --separate-git-dir "$gitdir" - fi || + git clone $quiet -n ${reference:+"$reference"} \ + --separate-git-dir "$gitdir" "$url" "$path" || 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)/ + # 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 $a | sed -e 's|[^/]*|..|g') + (clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b") } #