Code

i18n: git-submodule "Submodule change[...]" messages
[git.git] / git-submodule.sh
index b010a673097a9cfcf009b307114669b6221d066c..60ea58e31b6fb1b586540766286f7bcc9b2f2fc6 100755 (executable)
@@ -8,12 +8,13 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
 USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
-   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
+   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
    or: $dashless [--quiet] sync [--] [<path>...]"
 OPTIONS_SPEC=
 . git-sh-setup
+. git-sh-i18n
 . git-parse-remote
 require_work_tree
 
@@ -34,7 +35,7 @@ resolve_relative_url ()
 {
        remote=$(get_default_remote)
        remoteurl=$(git config "remote.$remote.url") ||
-               die "remote ($remote) does not have a url defined in .git/config"
+               die "$(eval_gettext "remote (\$remote) does not have a url defined in .git/config")"
        url="$1"
        remoteurl=${remoteurl%/}
        sep=/
@@ -52,7 +53,7 @@ resolve_relative_url ()
                                sep=:
                                ;;
                        *)
-                               die "cannot strip one component off url '$remoteurl'"
+                               die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
                                ;;
                        esac
                        ;;
@@ -104,7 +105,7 @@ module_name()
        name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
                sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
        test -z "$name" &&
-       die "No submodule mapping found in .gitmodules for path '$path'"
+       die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$path'")"
        echo "$name"
 }
 
@@ -128,7 +129,7 @@ module_clone()
        else
                git-clone -n "$url" "$path"
        fi ||
-       die "Clone of '$url' into submodule path '$path' failed"
+       die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
 }
 
 #
@@ -201,7 +202,7 @@ cmd_add()
                realrepo=$repo
                ;;
        *)
-               die "repo URL: '$repo' must be absolute or begin with ./|../"
+               die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
        ;;
        esac
 
@@ -218,7 +219,7 @@ cmd_add()
                        s|/*$||
                ')
        git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
-       die "'$path' already exists in the index"
+       die "$(eval_gettext "'\$path' already exists in the index")"
 
        if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
        then
@@ -233,9 +234,9 @@ cmd_add()
        then
                if test -d "$path"/.git -o -f "$path"/.git
                then
-                       echo "Adding existing repo at '$path' to the index"
+                       eval_gettext "Adding existing repo at '\$path' to the index"; echo
                else
-                       die "'$path' already exists and is not a valid git repo"
+                       die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
                fi
 
                case "$repo" in
@@ -258,16 +259,16 @@ cmd_add()
                        '') git checkout -f -q ;;
                        ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
                        esac
-               ) || die "Unable to checkout submodule '$path'"
+               ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
        fi
 
        git add $force "$path" ||
-       die "Failed to add submodule '$path'"
+       die "$(eval_gettext "Failed to add submodule '\$path'")"
 
        git config -f .gitmodules submodule."$path".path "$path" &&
        git config -f .gitmodules submodule."$path".url "$repo" &&
        git add --force .gitmodules ||
-       die "Failed to register submodule '$path'"
+       die "$(eval_gettext "Failed to register submodule '\$path'")"
 }
 
 #
@@ -317,7 +318,7 @@ cmd_foreach()
                                        cmd_foreach "--recursive" "$@"
                                fi
                        ) ||
-                       die "Stopping at '$path'; script returned non-zero status."
+                       die "$(eval_gettext "Stopping at '\$path'; script returned non-zero status.")"
                fi
        done
 }
@@ -360,7 +361,7 @@ cmd_init()
 
                url=$(git config -f .gitmodules submodule."$name".url)
                test -z "$url" &&
-               die "No url found for submodule path '$path' in .gitmodules"
+               die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
 
                # Possibly a url relative to parent
                case "$url" in
@@ -370,14 +371,14 @@ cmd_init()
                esac
 
                git config submodule."$name".url "$url" ||
-               die "Failed to register url for submodule path '$path'"
+               die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
 
                upd="$(git config -f .gitmodules submodule."$name".update)"
                test -z "$upd" ||
                git config submodule."$name".update "$upd" ||
-               die "Failed to register update mode for submodule path '$path'"
+               die "$(eval_gettext "Failed to register update mode for submodule path '\$path'")"
 
-               say "Submodule '$name' ($url) registered for path '$path'"
+               say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$path'")"
        done
 }
 
@@ -402,6 +403,9 @@ cmd_update()
                -N|--no-fetch)
                        nofetch=1
                        ;;
+               -f|--force)
+                       force=$1
+                       ;;
                -r|--rebase)
                        update="rebase"
                        ;;
@@ -470,7 +474,7 @@ cmd_update()
                else
                        subsha1=$(clear_local_git_env; cd "$path" &&
                                git rev-parse --verify HEAD) ||
-                       die "Unable to find current revision in submodule path '$path'"
+                       die "$(eval_gettext "Unable to find current revision in submodule path '\$path'")"
                fi
 
                if ! test -z "$update"
@@ -480,10 +484,11 @@ cmd_update()
 
                if test "$subsha1" != "$sha1"
                then
-                       force=
-                       if test -z "$subsha1"
+                       subforce=$force
+                       # If we don't already have a -f flag and the submodule has never been checked out
+                       if test -z "$subsha1" -a -z "$force"
                        then
-                               force="-f"
+                               subforce="-f"
                        fi
 
                        if test -z "$nofetch"
@@ -493,7 +498,7 @@ cmd_update()
                                (clear_local_git_env; cd "$path" &&
                                        ((rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
                                         test -z "$rev") || git-fetch)) ||
-                               die "Unable to fetch in submodule path '$path'"
+                               die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
                        fi
 
                        # Is this something we just cloned?
@@ -506,30 +511,29 @@ cmd_update()
                        case "$update_module" in
                        rebase)
                                command="git rebase"
-                               action="rebase"
-                               msg="rebased onto"
+                               die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$path'")"
+                               say_msg="$(eval_gettext "Submodule path '\$path': rebased into '\$sha1'")"
                                ;;
                        merge)
                                command="git merge"
-                               action="merge"
-                               msg="merged in"
+                               die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$path'")"
+                               say_msg="$(eval_gettext "Submodule path '\$path': merged in '\$sha1'")"
                                ;;
                        *)
-                               command="git checkout $force -q"
-                               action="checkout"
-                               msg="checked out"
+                               command="git checkout $subforce -q"
+                               die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$path'")"
+                               say_msg="$(eval_gettext "Submodule path '\$path': checked out '\$sha1'")"
                                ;;
                        esac
 
-                       (clear_local_git_env; cd "$path" && $command "$sha1") ||
-                       die "Unable to $action '$sha1' in submodule path '$path'"
-                       say "Submodule path '$path': $msg '$sha1'"
+                       (clear_local_git_env; cd "$path" && $command "$sha1") || die $die_msg
+                       say $say_msg
                fi
 
                if test -n "$recursive"
                then
                        (clear_local_git_env; cd "$path" && eval cmd_update "$orig_flags") ||
-                       die "Failed to recurse into submodule path '$path'"
+                       die "$(eval_gettext "Failed to recurse into submodule path '\$path'")"
                fi
        done
 }
@@ -613,7 +617,7 @@ cmd_summary() {
        if [ -n "$files" ]
        then
                test -n "$cached" &&
-               die "--cached cannot be used with --files"
+               die "$(gettext -- "--cached cannot be used with --files")"
                diff_cmd=diff-files
                head=
        fi
@@ -653,7 +657,10 @@ cmd_summary() {
                                ;; # removed
                        *)
                                # unexpected type
-                               echo >&2 "unexpected mode $mod_dst"
+                               (
+                                       eval_gettext "unexpected mode \$mod_dst" &&
+                                       echo
+                               ) >&2
                                continue ;;
                        esac
                fi
@@ -738,9 +745,9 @@ cmd_summary() {
        done |
        if test -n "$for_status"; then
                if [ -n "$files" ]; then
-                       echo "# Submodules changed but not updated:"
+                       gettext "# Submodules changed but not updated:"; echo
                else
-                       echo "# Submodule changes to be committed:"
+                       gettext "# Submodule changes to be committed:"; echo
                fi
                echo "#"
                sed -e 's|^|# |' -e 's|^# $|#|'
@@ -826,7 +833,7 @@ cmd_status()
                                cd "$path" &&
                                eval cmd_status "$orig_args"
                        ) ||
-                       die "Failed to recurse into submodule path '$path'"
+                       die "$(eval_gettext "Failed to recurse into submodule path '\$path'")"
                fi
        done
 }
@@ -870,7 +877,7 @@ cmd_sync()
                        ;;
                esac
 
-               say "Synchronizing submodule url for '$name'"
+               say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
                git config submodule."$name".url "$url"
 
                if test -e "$path"/.git