README: tutorial.txt is now called gittutorial.txt
[gitweb.git] / git-submodule.sh
index 100737210de3c76682ab3803626a36328fb27ca1..21e5b5b7daf341a59b9496b235adcceafe4f2c8c 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
@@ -73,7 +73,7 @@ resolve_relative_url ()
 module_name()
 {
        # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
-       re=$(printf '%s' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
+       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" &&
@@ -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
 
@@ -269,6 +269,7 @@ cmd_update()
        do
                case "$1" in
                -q|--quiet)
+                       shift
                        quiet=1
                        ;;
                -i|--init)
@@ -286,7 +287,6 @@ cmd_update()
                        break
                        ;;
                esac
-               shift
        done
 
        git ls-files --stage -- "$@" | grep '^160000 ' |