Code

http-fetch: do not SEGV after fetching a bad pack idx file
[git.git] / git-submodule.sh
index 403283090775141d884aa248ceb6c629e57912bb..099a7d7560879c284c9fb2fff68f4588baaaf49b 100755 (executable)
@@ -45,8 +45,8 @@ resolve_relative_url ()
        branch="$(git symbolic-ref HEAD 2>/dev/null)"
        remote="$(git config branch.${branch#refs/heads/}.remote)"
        remote="${remote:-origin}"
-       remoteurl="$(git config remote.$remote.url)" ||
-               die "remote ($remote) does not have a url in .git/config"
+       remoteurl=$(git config "remote.$remote.url") ||
+               die "remote ($remote) does not have a url defined in .git/config"
        url="$1"
        while test -n "$url"
        do
@@ -167,8 +167,7 @@ cmd_add()
        # perhaps the path exists and is already a git repo, else clone it
        if test -e "$path"
        then
-               if test -d "$path/.git" &&
-               test "$(unset GIT_DIR; cd $path; git rev-parse --git-dir)" = ".git"
+               if test -d "$path"/.git -o -f "$path"/.git
                then
                        echo "Adding existing repo at '$path' to the index"
                else
@@ -178,7 +177,8 @@ cmd_add()
                case "$repo" in
                ./*|../*)
                        # dereference source url relative to parent's url
-                       realrepo="$(resolve_relative_url $repo)" ;;
+                       realrepo=$(resolve_relative_url "$repo") || exit
+                       ;;
                *)
                        # Turn the source into an absolute path if
                        # it is local
@@ -246,7 +246,7 @@ cmd_init()
                # Possibly a url relative to parent
                case "$url" in
                ./*|../*)
-                       url="$(resolve_relative_url "$url")"
+                       url=$(resolve_relative_url "$url") || exit
                        ;;
                esac