Code

t1300: test mixed-case variable retrieval
[git.git] / git-submodule.sh
index 87c9452c8a8ae179ffb7e7958ba95688e95bd0e9..814d0d914eaf994462e61559b0692c958f97513b 100755 (executable)
@@ -35,7 +35,7 @@ resolve_relative_url ()
 {
        remote=$(get_default_remote)
        remoteurl=$(git config "remote.$remote.url") ||
-               die "$(eval_gettext "remote (\$remote) does not have a url defined in .git/config")"
+               remoteurl=$(pwd) # the repository is its own authoritative upstream
        url="$1"
        remoteurl=${remoteurl%/}
        sep=/
@@ -122,12 +122,17 @@ module_clone()
        path=$1
        url=$2
        reference="$3"
+       quiet=
+       if test -n "$GIT_QUIET"
+       then
+               quiet=-q
+       fi
 
        if test -n "$reference"
        then
-               git-clone "$reference" -n "$url" "$path"
+               git-clone $quiet "$reference" -n "$url" "$path"
        else
-               git-clone -n "$url" "$path"
+               git-clone $quiet -n "$url" "$path"
        fi ||
        die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
 }
@@ -223,12 +228,9 @@ cmd_add()
 
        if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
        then
-               (
-                       eval_gettext "The following path is ignored by one of your .gitignore files:
+               eval_gettextln "The following path is ignored by one of your .gitignore files:
 \$path
-Use -f if you really want to add it." &&
-                       echo
-               ) >&2
+Use -f if you really want to add it." >&2
                exit 1
        fi
 
@@ -237,20 +239,11 @@ Use -f if you really want to add it." &&
        then
                if test -d "$path"/.git -o -f "$path"/.git
                then
-                       eval_gettext "Adding existing repo at '\$path' to the index"; echo
+                       eval_gettextln "Adding existing repo at '\$path' to the index"
                else
                        die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
                fi
 
-               case "$repo" in
-               ./*|../*)
-                       url=$(resolve_relative_url "$repo") || exit
-                   ;;
-               *)
-                       url="$repo"
-                       ;;
-               esac
-               git config submodule."$path".url "$url"
        else
 
                module_clone "$path" "$realrepo" "$reference" || exit
@@ -264,6 +257,7 @@ Use -f if you really want to add it." &&
                        esac
                ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
        fi
+       git config submodule."$path".url "$realrepo"
 
        git add $force "$path" ||
        die "$(eval_gettext "Failed to add submodule '\$path'")"
@@ -363,25 +357,26 @@ cmd_init()
        do
                # Skip already registered paths
                name=$(module_name "$path") || exit
-               url=$(git config submodule."$name".url)
-               test -z "$url" || continue
-
-               url=$(git config -f .gitmodules submodule."$name".url)
-               test -z "$url" &&
-               die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
-
-               # Possibly a url relative to parent
-               case "$url" in
-               ./*|../*)
-                       url=$(resolve_relative_url "$url") || exit
-                       ;;
-               esac
-
-               git config submodule."$name".url "$url" ||
-               die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
+               if test -z "$(git config "submodule.$name.url")"
+               then
+                       url=$(git config -f .gitmodules submodule."$name".url)
+                       test -z "$url" &&
+                       die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
+
+                       # Possibly a url relative to parent
+                       case "$url" in
+                       ./*|../*)
+                               url=$(resolve_relative_url "$url") || exit
+                               ;;
+                       esac
+                       git config submodule."$name".url "$url" ||
+                       die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
+               fi
 
+               # Copy "update" setting when it is not set yet
                upd="$(git config -f .gitmodules submodule."$name".update)"
                test -z "$upd" ||
+               test -n "$(git config submodule."$name".update)" ||
                git config submodule."$name".update "$upd" ||
                die "$(eval_gettext "Failed to register update mode for submodule path '\$path'")"
 
@@ -703,10 +698,7 @@ cmd_summary() {
                                ;; # removed
                        *)
                                # unexpected type
-                               (
-                                       eval_gettext "unexpected mode \$mod_dst" &&
-                                       echo
-                               ) >&2
+                               eval_gettextln "unexpected mode \$mod_dst" >&2
                                continue ;;
                        esac
                fi
@@ -793,9 +785,9 @@ cmd_summary() {
        done |
        if test -n "$for_status"; then
                if [ -n "$files" ]; then
-                       gettext "# Submodules changed but not updated:"; echo
+                       gettextln "# Submodules changed but not updated:"
                else
-                       gettext "# Submodule changes to be committed:"; echo
+                       gettextln "# Submodule changes to be committed:"
                fi
                echo "#"
                sed -e 's|^|# |' -e 's|^# $|#|'
@@ -925,17 +917,20 @@ cmd_sync()
                        ;;
                esac
 
-               say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
-               git config submodule."$name".url "$url"
-
-               if test -e "$path"/.git
+               if git config "submodule.$name.url" >/dev/null 2>/dev/null
                then
-               (
-                       clear_local_git_env
-                       cd "$path"
-                       remote=$(get_default_remote)
-                       git config remote."$remote".url "$url"
-               )
+                       say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
+                       git config submodule."$name".url "$url"
+
+                       if test -e "$path"/.git
+                       then
+                       (
+                               clear_local_git_env
+                               cd "$path"
+                               remote=$(get_default_remote)
+                               git config remote."$remote".url "$url"
+                       )
+                       fi
                fi
        done
 }