cherry-pick: add --allow-empty-message option
[gitweb.git] / builtin / remote.c
index 7f3514b7087cb92bb54278cbc1fffdb0881d41b8..920262d76ec9bdc40a8ad7703cf1eb972a40eb9e 100644 (file)
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
@@ -9,15 +9,15 @@
 
 static const char * const builtin_remote_usage[] = {
        "git remote [-v | --verbose]",
-       "git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>",
+       "git remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror=<fetch|push>] <name> <url>",
        "git remote rename <old> <new>",
        "git remote rm <name>",
        "git remote set-head <name> (-a | -d | <branch>)",
        "git remote [-v | --verbose] show [-n] <name>",
        "git remote prune [-n | --dry-run] <name>",
-       "git remote [-v | --verbose] update [-p | --prune] [group | remote]",
+       "git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]",
        "git remote set-branches [--add] <name> <branch>...",
-       "git remote set-url <name> <newurl> [<oldurl>]",
+       "git remote set-url [--push] <name> <newurl> [<oldurl>]",
        "git remote set-url --add <name> <newurl>",
        "git remote set-url --delete <name> <url>",
        NULL
@@ -88,16 +88,6 @@ static inline int postfixcmp(const char *string, const char *postfix)
        return strcmp(string + len1 - len2, postfix);
 }
 
-static int opt_parse_track(const struct option *opt, const char *arg, int not)
-{
-       struct string_list *list = opt->value;
-       if (not)
-               string_list_clear(list, 0);
-       else
-               string_list_append(arg, list);
-       return 0;
-}
-
 static int fetch_remote(const char *name)
 {
        const char *argv[] = { "fetch", name, NULL, NULL };
@@ -105,12 +95,23 @@ static int fetch_remote(const char *name)
                argv[1] = "-v";
                argv[2] = name;
        }
-       printf("Updating %s\n", name);
+       printf_ln(_("Updating %s"), name);
        if (run_command_v_opt(argv, RUN_GIT_CMD))
-               return error("Could not fetch %s", name);
+               return error(_("Could not fetch %s"), name);
        return 0;
 }
 
+enum {
+       TAGS_UNSET = 0,
+       TAGS_DEFAULT = 1,
+       TAGS_SET = 2
+};
+
+#define MIRROR_NONE 0
+#define MIRROR_FETCH 1
+#define MIRROR_PUSH 2
+#define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH)
+
 static int add_branch(const char *key, const char *branchname,
                const char *remotename, int mirror, struct strbuf *tmp)
 {
@@ -125,10 +126,33 @@ static int add_branch(const char *key, const char *branchname,
        return git_config_set_multivar(key, tmp->buf, "^$", 0);
 }
 
+static const char mirror_advice[] =
+N_("--mirror is dangerous and deprecated; please\n"
+   "\t use --mirror=fetch or --mirror=push instead");
+
+static int parse_mirror_opt(const struct option *opt, const char *arg, int not)
+{
+       unsigned *mirror = opt->value;
+       if (not)
+               *mirror = MIRROR_NONE;
+       else if (!arg) {
+               warning("%s", _(mirror_advice));
+               *mirror = MIRROR_BOTH;
+       }
+       else if (!strcmp(arg, "fetch"))
+               *mirror = MIRROR_FETCH;
+       else if (!strcmp(arg, "push"))
+               *mirror = MIRROR_PUSH;
+       else
+               return error(_("unknown mirror argument: %s"), arg);
+       return 0;
+}
+
 static int add(int argc, const char **argv)
 {
-       int fetch = 0, mirror = 0;
-       struct string_list track = { NULL, 0, 0 };
+       int fetch = 0, fetch_tags = TAGS_DEFAULT;
+       unsigned mirror = MIRROR_NONE;
+       struct string_list track = STRING_LIST_INIT_NODUP;
        const char *master = NULL;
        struct remote *remote;
        struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
@@ -137,10 +161,17 @@ static int add(int argc, const char **argv)
 
        struct option options[] = {
                OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
-               OPT_CALLBACK('t', "track", &track, "branch",
-                       "branch(es) to track", opt_parse_track),
+               OPT_SET_INT(0, "tags", &fetch_tags,
+                           "import all tags and associated objects when fetching",
+                           TAGS_SET),
+               OPT_SET_INT(0, NULL, &fetch_tags,
+                           "or do not fetch any tag at all (--no-tags)", TAGS_UNSET),
+               OPT_STRING_LIST('t', "track", &track, "branch",
+                               "branch(es) to track"),
                OPT_STRING('m', "master", &master, "branch", "master branch"),
-               OPT_BOOLEAN(0, "mirror", &mirror, "no separate remotes"),
+               { OPTION_CALLBACK, 0, "mirror", &mirror, "push|fetch",
+                       "set up remote as a mirror to push to or fetch from",
+                       PARSE_OPT_OPTARG, parse_mirror_opt },
                OPT_END()
        };
 
@@ -150,40 +181,54 @@ static int add(int argc, const char **argv)
        if (argc < 2)
                usage_with_options(builtin_remote_add_usage, options);
 
+       if (mirror && master)
+               die(_("specifying a master branch makes no sense with --mirror"));
+       if (mirror && !(mirror & MIRROR_FETCH) && track.nr)
+               die(_("specifying branches to track makes sense only with fetch mirrors"));
+
        name = argv[0];
        url = argv[1];
 
        remote = remote_get(name);
        if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||
                        remote->fetch_refspec_nr))
-               die("remote %s already exists.", name);
+               die(_("remote %s already exists."), name);
 
        strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
        if (!valid_fetch_refspec(buf2.buf))
-               die("'%s' is not a valid remote name", name);
+               die(_("'%s' is not a valid remote name"), name);
 
        strbuf_addf(&buf, "remote.%s.url", name);
        if (git_config_set(buf.buf, url))
                return 1;
 
-       strbuf_reset(&buf);
-       strbuf_addf(&buf, "remote.%s.fetch", name);
-
-       if (track.nr == 0)
-               string_list_append("*", &track);
-       for (i = 0; i < track.nr; i++) {
-               if (add_branch(buf.buf, track.items[i].string,
-                               name, mirror, &buf2))
-                       return 1;
+       if (!mirror || mirror & MIRROR_FETCH) {
+               strbuf_reset(&buf);
+               strbuf_addf(&buf, "remote.%s.fetch", name);
+               if (track.nr == 0)
+                       string_list_append(&track, "*");
+               for (i = 0; i < track.nr; i++) {
+                       if (add_branch(buf.buf, track.items[i].string,
+                                      name, mirror, &buf2))
+                               return 1;
+               }
        }
 
-       if (mirror) {
+       if (mirror & MIRROR_PUSH) {
                strbuf_reset(&buf);
                strbuf_addf(&buf, "remote.%s.mirror", name);
                if (git_config_set(buf.buf, "true"))
                        return 1;
        }
 
+       if (fetch_tags != TAGS_DEFAULT) {
+               strbuf_reset(&buf);
+               strbuf_addf(&buf, "remote.%s.tagopt", name);
+               if (git_config_set(buf.buf,
+                       fetch_tags == TAGS_SET ? "--tags" : "--no-tags"))
+                       return 1;
+       }
+
        if (fetch && fetch_remote(name))
                return 1;
 
@@ -195,7 +240,7 @@ static int add(int argc, const char **argv)
                strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master);
 
                if (create_symref(buf.buf, buf2.buf, "remote add"))
-                       return error("Could not setup master '%s'", master);
+                       return error(_("Could not setup master '%s'"), master);
        }
 
        strbuf_release(&buf);
@@ -244,14 +289,14 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                } else
                        return 0;
 
-               item = string_list_insert(name, &branch_list);
+               item = string_list_insert(&branch_list, name);
 
                if (!item->util)
                        item->util = xcalloc(sizeof(struct branch_info), 1);
                info = item->util;
                if (type == REMOTE) {
                        if (info->remote_name)
-                               warning("more than one %s", orig_key);
+                               warning(_("more than one %s"), orig_key);
                        info->remote_name = xstrdup(value);
                } else if (type == MERGE) {
                        char *space = strchr(value, ' ');
@@ -259,11 +304,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
                        while (space) {
                                char *merge;
                                merge = xstrndup(value, space - value);
-                               string_list_append(merge, &info->merge);
+                               string_list_append(&info->merge, merge);
                                value = abbrev_branch(space + 1);
                                space = strchr(value, ' ');
                        }
-                       string_list_append(xstrdup(value), &info->merge);
+                       string_list_append(&info->merge, xstrdup(value));
                } else
                        info->rebase = git_config_bool(orig_key, value);
        }
@@ -291,23 +336,23 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
 
        for (i = 0; i < states->remote->fetch_refspec_nr; i++)
                if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1))
-                       die("Could not get fetch map for refspec %s",
+                       die(_("Could not get fetch map for refspec %s"),
                                states->remote->fetch_refspec[i]);
 
        states->new.strdup_strings = 1;
        states->tracked.strdup_strings = 1;
        states->stale.strdup_strings = 1;
        for (ref = fetch_map; ref; ref = ref->next) {
-               unsigned char sha1[20];
-               if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
-                       string_list_append(abbrev_branch(ref->name), &states->new);
+               if (!ref->peer_ref || !ref_exists(ref->peer_ref->name))
+                       string_list_append(&states->new, abbrev_branch(ref->name));
                else
-                       string_list_append(abbrev_branch(ref->name), &states->tracked);
+                       string_list_append(&states->tracked, abbrev_branch(ref->name));
        }
-       stale_refs = get_stale_heads(states->remote, fetch_map);
+       stale_refs = get_stale_heads(states->remote->fetch,
+                                    states->remote->fetch_refspec_nr, fetch_map);
        for (ref = stale_refs; ref; ref = ref->next) {
                struct string_list_item *item =
-                       string_list_append(abbrev_branch(ref->name), &states->stale);
+                       string_list_append(&states->stale, abbrev_branch(ref->name));
                item->util = xstrdup(ref->name);
        }
        free_refs(stale_refs);
@@ -329,7 +374,7 @@ struct push_info {
                PUSH_STATUS_UPTODATE,
                PUSH_STATUS_FASTFORWARD,
                PUSH_STATUS_OUTOFDATE,
-               PUSH_STATUS_NOTQUERIED,
+               PUSH_STATUS_NOTQUERIED
        } status;
 };
 
@@ -344,8 +389,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
        local_refs = get_local_heads();
        push_map = copy_ref_list(remote_refs);
 
-       match_refs(local_refs, &push_map, remote->push_refspec_nr,
-                  remote->push_refspec, MATCH_REFS_NONE);
+       match_push_refs(local_refs, &push_map, remote->push_refspec_nr,
+                       remote->push_refspec, MATCH_REFS_NONE);
 
        states->push.strdup_strings = 1;
        for (ref = push_map; ref; ref = ref->next) {
@@ -356,8 +401,8 @@ static int get_push_ref_states(const struct ref *remote_refs,
                        continue;
                hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
 
-               item = string_list_append(abbrev_branch(ref->peer_ref->name),
-                                         &states->push);
+               item = string_list_append(&states->push,
+                                         abbrev_branch(ref->peer_ref->name));
                item->util = xcalloc(sizeof(struct push_info), 1);
                info = item->util;
                info->forced = ref->force;
@@ -392,7 +437,7 @@ static int get_push_ref_states_noquery(struct ref_states *states)
 
        states->push.strdup_strings = 1;
        if (!remote->push_refspec_nr) {
-               item = string_list_append("(matching)", &states->push);
+               item = string_list_append(&states->push, _("(matching)"));
                info = item->util = xcalloc(sizeof(struct push_info), 1);
                info->status = PUSH_STATUS_NOTQUERIED;
                info->dest = xstrdup(item->string);
@@ -400,11 +445,11 @@ static int get_push_ref_states_noquery(struct ref_states *states)
        for (i = 0; i < remote->push_refspec_nr; i++) {
                struct refspec *spec = remote->push + i;
                if (spec->matching)
-                       item = string_list_append("(matching)", &states->push);
+                       item = string_list_append(&states->push, _("(matching)"));
                else if (strlen(spec->src))
-                       item = string_list_append(spec->src, &states->push);
+                       item = string_list_append(&states->push, spec->src);
                else
-                       item = string_list_append("(delete)", &states->push);
+                       item = string_list_append(&states->push, _("(delete)"));
 
                info = item->util = xcalloc(sizeof(struct push_info), 1);
                info->forced = spec->force;
@@ -428,7 +473,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
        matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
                                    fetch_map, 1);
        for (ref = matches; ref; ref = ref->next)
-               string_list_append(abbrev_branch(ref->name), &states->heads);
+               string_list_append(&states->heads, abbrev_branch(ref->name));
 
        free_refs(fetch_map);
        free_refs(matches);
@@ -488,12 +533,12 @@ static int add_branch_for_removal(const char *refname,
                        return 0;
        }
 
-       /* don't delete non-remote refs */
-       if (prefixcmp(refname, "refs/remotes")) {
+       /* don't delete non-remote-tracking refs */
+       if (prefixcmp(refname, "refs/remotes/")) {
                /* advise user how to delete local branches */
                if (!prefixcmp(refname, "refs/heads/"))
-                       string_list_append(abbrev_branch(refname),
-                                          branches->skipped);
+                       string_list_append(branches->skipped,
+                                          abbrev_branch(refname));
                /* silently skip over other non-remote refs */
                return 0;
        }
@@ -502,7 +547,7 @@ static int add_branch_for_removal(const char *refname,
        if (flags & REF_ISSYMREF)
                return unlink(git_path("%s", refname));
 
-       item = string_list_append(refname, branches->branches);
+       item = string_list_append(branches->branches, refname);
        item->util = xmalloc(20);
        hashcpy(item->util, sha1);
 
@@ -525,10 +570,10 @@ static int read_remote_branches(const char *refname,
        unsigned char orig_sha1[20];
        const char *symref;
 
-       strbuf_addf(&buf, "refs/remotes/%s", rename->old);
+       strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
        if (!prefixcmp(refname, buf.buf)) {
-               item = string_list_append(xstrdup(refname), rename->remote_branches);
-               symref = resolve_ref(refname, orig_sha1, 1, &flag);
+               item = string_list_append(rename->remote_branches, xstrdup(refname));
+               symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
                if (flag & REF_ISSYMREF)
                        item->util = xstrdup(symref);
                else
@@ -547,19 +592,19 @@ static int migrate_file(struct remote *remote)
        strbuf_addf(&buf, "remote.%s.url", remote->name);
        for (i = 0; i < remote->url_nr; i++)
                if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0))
-                       return error("Could not append '%s' to '%s'",
+                       return error(_("Could not append '%s' to '%s'"),
                                        remote->url[i], buf.buf);
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.push", remote->name);
        for (i = 0; i < remote->push_refspec_nr; i++)
                if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0))
-                       return error("Could not append '%s' to '%s'",
+                       return error(_("Could not append '%s' to '%s'"),
                                        remote->push_refspec[i], buf.buf);
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.fetch", remote->name);
        for (i = 0; i < remote->fetch_refspec_nr; i++)
                if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0))
-                       return error("Could not append '%s' to '%s'",
+                       return error(_("Could not append '%s' to '%s'"),
                                        remote->fetch_refspec[i], buf.buf);
        if (remote->origin == REMOTE_REMOTES)
                path = git_path("remotes/%s", remote->name);
@@ -576,10 +621,11 @@ static int mv(int argc, const char **argv)
                OPT_END()
        };
        struct remote *oldremote, *newremote;
-       struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
-       struct string_list remote_branches = { NULL, 0, 0, 0 };
+       struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT,
+               old_remote_context = STRBUF_INIT;
+       struct string_list remote_branches = STRING_LIST_INIT_NODUP;
        struct rename_info rename;
-       int i;
+       int i, refspec_updated = 0;
 
        if (argc != 3)
                usage_with_options(builtin_remote_rename_usage, options);
@@ -590,41 +636,51 @@ static int mv(int argc, const char **argv)
 
        oldremote = remote_get(rename.old);
        if (!oldremote)
-               die("No such remote: %s", rename.old);
+               die(_("No such remote: %s"), rename.old);
 
        if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG)
                return migrate_file(oldremote);
 
        newremote = remote_get(rename.new);
        if (newremote && (newremote->url_nr > 1 || newremote->fetch_refspec_nr))
-               die("remote %s already exists.", rename.new);
+               die(_("remote %s already exists."), rename.new);
 
        strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new);
        if (!valid_fetch_refspec(buf.buf))
-               die("'%s' is not a valid remote name", rename.new);
+               die(_("'%s' is not a valid remote name"), rename.new);
 
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s", rename.old);
        strbuf_addf(&buf2, "remote.%s", rename.new);
        if (git_config_rename_section(buf.buf, buf2.buf) < 1)
-               return error("Could not rename config section '%s' to '%s'",
+               return error(_("Could not rename config section '%s' to '%s'"),
                                buf.buf, buf2.buf);
 
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.fetch", rename.new);
        if (git_config_set_multivar(buf.buf, NULL, NULL, 1))
-               return error("Could not remove config section '%s'", buf.buf);
+               return error(_("Could not remove config section '%s'"), buf.buf);
+       strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
        for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
                char *ptr;
 
                strbuf_reset(&buf2);
                strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
-               ptr = strstr(buf2.buf, rename.old);
-               if (ptr)
-                       strbuf_splice(&buf2, ptr-buf2.buf, strlen(rename.old),
-                                       rename.new, strlen(rename.new));
+               ptr = strstr(buf2.buf, old_remote_context.buf);
+               if (ptr) {
+                       refspec_updated = 1;
+                       strbuf_splice(&buf2,
+                                     ptr-buf2.buf + strlen(":refs/remotes/"),
+                                     strlen(rename.old), rename.new,
+                                     strlen(rename.new));
+               } else
+                       warning(_("Not updating non-default fetch refspec\n"
+                                 "\t%s\n"
+                                 "\tPlease update the configuration manually if necessary."),
+                               buf2.buf);
+
                if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
-                       return error("Could not append '%s'", buf.buf);
+                       return error(_("Could not append '%s'"), buf.buf);
        }
 
        read_branches();
@@ -635,11 +691,14 @@ static int mv(int argc, const char **argv)
                        strbuf_reset(&buf);
                        strbuf_addf(&buf, "branch.%s.remote", item->string);
                        if (git_config_set(buf.buf, rename.new)) {
-                               return error("Could not set '%s'", buf.buf);
+                               return error(_("Could not set '%s'"), buf.buf);
                        }
                }
        }
 
+       if (!refspec_updated)
+               return 0;
+
        /*
         * First remove symrefs, then rename the rest, finally create
         * the new symrefs.
@@ -650,11 +709,11 @@ static int mv(int argc, const char **argv)
                int flag = 0;
                unsigned char sha1[20];
 
-               resolve_ref(item->string, sha1, 1, &flag);
+               read_ref_full(item->string, sha1, 1, &flag);
                if (!(flag & REF_ISSYMREF))
                        continue;
                if (delete_ref(item->string, NULL, REF_NODEREF))
-                       die("deleting '%s' failed", item->string);
+                       die(_("deleting '%s' failed"), item->string);
        }
        for (i = 0; i < remote_branches.nr; i++) {
                struct string_list_item *item = remote_branches.items + i;
@@ -669,7 +728,7 @@ static int mv(int argc, const char **argv)
                strbuf_addf(&buf2, "remote: renamed %s to %s",
                                item->string, buf.buf);
                if (rename_ref(item->string, buf.buf, buf2.buf))
-                       die("renaming '%s' failed", item->string);
+                       die(_("renaming '%s' failed"), item->string);
        }
        for (i = 0; i < remote_branches.nr; i++) {
                struct string_list_item *item = remote_branches.items + i;
@@ -688,7 +747,7 @@ static int mv(int argc, const char **argv)
                strbuf_addf(&buf3, "remote: renamed %s to %s",
                                item->string, buf.buf);
                if (create_symref(buf.buf, buf2.buf, buf3.buf))
-                       die("creating '%s' failed", buf.buf);
+                       die(_("creating '%s' failed"), buf.buf);
        }
        return 0;
 }
@@ -702,7 +761,7 @@ static int remove_branches(struct string_list *branches)
                unsigned char *sha1 = item->util;
 
                if (delete_ref(refname, sha1, 0))
-                       result |= error("Could not remove branch %s", refname);
+                       result |= error(_("Could not remove branch %s"), refname);
        }
        return result;
 }
@@ -715,26 +774,29 @@ static int rm(int argc, const char **argv)
        struct remote *remote;
        struct strbuf buf = STRBUF_INIT;
        struct known_remotes known_remotes = { NULL, NULL };
-       struct string_list branches = { NULL, 0, 0, 1 };
-       struct string_list skipped = { NULL, 0, 0, 1 };
-       struct branches_for_remote cb_data = {
-               NULL, &branches, &skipped, &known_remotes
-       };
+       struct string_list branches = STRING_LIST_INIT_DUP;
+       struct string_list skipped = STRING_LIST_INIT_DUP;
+       struct branches_for_remote cb_data;
        int i, result;
 
+       memset(&cb_data, 0, sizeof(cb_data));
+       cb_data.branches = &branches;
+       cb_data.skipped = &skipped;
+       cb_data.keep = &known_remotes;
+
        if (argc != 2)
                usage_with_options(builtin_remote_rm_usage, options);
 
        remote = remote_get(argv[1]);
        if (!remote)
-               die("No such remote: %s", argv[1]);
+               die(_("No such remote: %s"), argv[1]);
 
        known_remotes.to_delete = remote;
        for_each_remote(add_known_remote, &known_remotes);
 
        strbuf_addf(&buf, "remote.%s", remote->name);
        if (git_config_rename_section(buf.buf, NULL) < 1)
-               return error("Could not remove config section '%s'", buf.buf);
+               return error(_("Could not remove config section '%s'"), buf.buf);
 
        read_branches();
        for (i = 0; i < branch_list.nr; i++) {
@@ -768,11 +830,12 @@ static int rm(int argc, const char **argv)
        string_list_clear(&branches, 1);
 
        if (skipped.nr) {
-               fprintf(stderr, skipped.nr == 1 ?
-                       "Note: A non-remote branch was not removed; "
-                       "to delete it, use:\n" :
-                       "Note: Non-remote branches were not removed; "
-                       "to delete them, use:\n");
+               fprintf_ln(stderr,
+                          Q_("Note: A branch outside the refs/remotes/ hierarchy was not removed;\n"
+                             "to delete it, use:",
+                             "Note: Some branches outside the refs/remotes/ hierarchy were not removed;\n"
+                             "to delete them, use:",
+                             skipped.nr));
                for (i = 0; i < skipped.nr; i++)
                        fprintf(stderr, "  git branch -d %s\n",
                                skipped.items[i].string);
@@ -810,7 +873,7 @@ static int append_ref_to_tracked_list(const char *refname,
        memset(&refspec, 0, sizeof(refspec));
        refspec.dst = (char *)refname;
        if (!remote_find_tracking(states->remote, &refspec))
-               string_list_append(abbrev_branch(refspec.src), &states->tracked);
+               string_list_append(&states->tracked, abbrev_branch(refspec.src));
 
        return 0;
 }
@@ -824,7 +887,7 @@ static int get_remote_ref_states(const char *name,
 
        states->remote = remote_get(name);
        if (!states->remote)
-               return error("No such remote: %s", name);
+               return error(_("No such remote: %s"), name);
 
        read_branches();
 
@@ -863,7 +926,7 @@ static int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
        int n = strlen(item->string);
        if (n > info->width)
                info->width = n;
-       string_list_insert(item->string, info->list);
+       string_list_insert(info->list, item->string);
        return 0;
 }
 
@@ -877,14 +940,14 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data)
                const char *fmt = "%s";
                const char *arg = "";
                if (string_list_has_string(&states->new, name)) {
-                       fmt = " new (next fetch will store in remotes/%s)";
+                       fmt = _(" new (next fetch will store in remotes/%s)");
                        arg = states->remote->name;
                } else if (string_list_has_string(&states->tracked, name))
-                       arg = " tracked";
+                       arg = _(" tracked");
                else if (string_list_has_string(&states->stale, name))
-                       arg = " stale (use 'git remote prune' to remove)";
+                       arg = _(" stale (use 'git remote prune' to remove)");
                else
-                       arg = " ???";
+                       arg = _(" ???");
                printf("    %-*s", info->width, name);
                printf(fmt, arg);
                printf("\n");
@@ -910,7 +973,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
        if (branch_info->rebase)
                show_info->any_rebase = 1;
 
-       item = string_list_insert(branch_item->string, show_info->list);
+       item = string_list_insert(show_info->list, branch_item->string);
        item->util = branch_info;
 
        return 0;
@@ -925,21 +988,21 @@ static int show_local_info_item(struct string_list_item *item, void *cb_data)
        int i;
 
        if (branch_info->rebase && branch_info->merge.nr > 1) {
-               error("invalid branch.%s.merge; cannot rebase onto > 1 branch",
+               error(_("invalid branch.%s.merge; cannot rebase onto > 1 branch"),
                        item->string);
                return 0;
        }
 
        printf("    %-*s ", show_info->width, item->string);
        if (branch_info->rebase) {
-               printf("rebases onto remote %s\n", merge->items[0].string);
+               printf_ln(_("rebases onto remote %s"), merge->items[0].string);
                return 0;
        } else if (show_info->any_rebase) {
-               printf(" merges with remote %s\n", merge->items[0].string);
-               also = "    and with remote";
+               printf_ln(_(" merges with remote %s"), merge->items[0].string);
+               also = _("    and with remote");
        } else {
-               printf("merges with remote %s\n", merge->items[0].string);
-               also = "   and with remote";
+               printf_ln(_("merges with remote %s"), merge->items[0].string);
+               also = _("   and with remote");
        }
        for (i = 1; i < merge->nr; i++)
                printf("    %-*s %s %s\n", show_info->width, "", also,
@@ -958,7 +1021,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
                show_info->width = n;
        if ((n = strlen(push_info->dest)) > show_info->width2)
                show_info->width2 = n;
-       item = string_list_append(push_item->string, show_info->list);
+       item = string_list_append(show_info->list, push_item->string);
        item->util = push_item->util;
        return 0;
 }
@@ -981,36 +1044,43 @@ static int show_push_info_item(struct string_list_item *item, void *cb_data)
 {
        struct show_info *show_info = cb_data;
        struct push_info *push_info = item->util;
-       char *src = item->string, *status = NULL;
+       const char *src = item->string, *status = NULL;
 
        switch (push_info->status) {
        case PUSH_STATUS_CREATE:
-               status = "create";
+               status = _("create");
                break;
        case PUSH_STATUS_DELETE:
-               status = "delete";
-               src = "(none)";
+               status = _("delete");
+               src = _("(none)");
                break;
        case PUSH_STATUS_UPTODATE:
-               status = "up to date";
+               status = _("up to date");
                break;
        case PUSH_STATUS_FASTFORWARD:
-               status = "fast-forwardable";
+               status = _("fast-forwardable");
                break;
        case PUSH_STATUS_OUTOFDATE:
-               status = "local out of date";
+               status = _("local out of date");
                break;
        case PUSH_STATUS_NOTQUERIED:
                break;
        }
-       if (status)
-               printf("    %-*s %s to %-*s (%s)\n", show_info->width, src,
-                       push_info->forced ? "forces" : "pushes",
-                       show_info->width2, push_info->dest, status);
-       else
-               printf("    %-*s %s to %s\n", show_info->width, src,
-                       push_info->forced ? "forces" : "pushes",
-                       push_info->dest);
+       if (status) {
+               if (push_info->forced)
+                       printf_ln(_("    %-*s forces to %-*s (%s)"), show_info->width, src,
+                              show_info->width2, push_info->dest, status);
+               else
+                       printf_ln(_("    %-*s pushes to %-*s (%s)"), show_info->width, src,
+                              show_info->width2, push_info->dest, status);
+       } else {
+               if (push_info->forced)
+                       printf_ln(_("    %-*s forces to %s"), show_info->width, src,
+                              push_info->dest);
+               else
+                       printf_ln(_("    %-*s pushes to %s"), show_info->width, src,
+                              push_info->dest);
+       }
        return 0;
 }
 
@@ -1022,7 +1092,7 @@ static int show(int argc, const char **argv)
                OPT_END()
        };
        struct ref_states states;
-       struct string_list info_list = { NULL, 0, 0, 0 };
+       struct string_list info_list = STRING_LIST_INIT_NODUP;
        struct show_info info;
 
        argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,
@@ -1045,9 +1115,9 @@ static int show(int argc, const char **argv)
 
                get_remote_ref_states(*argv, &states, query_flag);
 
-               printf("* remote %s\n", *argv);
-               printf("  Fetch URL: %s\n", states.remote->url_nr > 0 ?
-                       states.remote->url[0] : "(no URL)");
+               printf_ln(_("* remote %s"), *argv);
+               printf_ln(_("  Fetch URL: %s"), states.remote->url_nr > 0 ?
+                      states.remote->url[0] : _("(no URL)"));
                if (states.remote->pushurl_nr) {
                        url = states.remote->pushurl;
                        url_nr = states.remote->pushurl_nr;
@@ -1055,58 +1125,61 @@ static int show(int argc, const char **argv)
                        url = states.remote->url;
                        url_nr = states.remote->url_nr;
                }
-               for (i=0; i < url_nr; i++)
-                       printf("  Push  URL: %s\n", url[i]);
+               for (i = 0; i < url_nr; i++)
+                       printf_ln(_("  Push  URL: %s"), url[i]);
                if (!i)
-                       printf("  Push  URL: %s\n", "(no URL)");
+                       printf_ln(_("  Push  URL: %s"), "(no URL)");
                if (no_query)
-                       printf("  HEAD branch: (not queried)\n");
+                       printf_ln(_("  HEAD branch: %s"), "(not queried)");
                else if (!states.heads.nr)
-                       printf("  HEAD branch: (unknown)\n");
+                       printf_ln(_("  HEAD branch: %s"), "(unknown)");
                else if (states.heads.nr == 1)
-                       printf("  HEAD branch: %s\n", states.heads.items[0].string);
+                       printf_ln(_("  HEAD branch: %s"), states.heads.items[0].string);
                else {
-                       printf("  HEAD branch (remote HEAD is ambiguous,"
-                              " may be one of the following):\n");
+                       printf(_("  HEAD branch (remote HEAD is ambiguous,"
+                                " may be one of the following):\n"));
                        for (i = 0; i < states.heads.nr; i++)
                                printf("    %s\n", states.heads.items[i].string);
                }
 
                /* remote branch info */
                info.width = 0;
-               for_each_string_list(add_remote_to_show_info, &states.new, &info);
-               for_each_string_list(add_remote_to_show_info, &states.tracked, &info);
-               for_each_string_list(add_remote_to_show_info, &states.stale, &info);
+               for_each_string_list(&states.new, add_remote_to_show_info, &info);
+               for_each_string_list(&states.tracked, add_remote_to_show_info, &info);
+               for_each_string_list(&states.stale, add_remote_to_show_info, &info);
                if (info.list->nr)
-                       printf("  Remote branch%s:%s\n",
-                              info.list->nr > 1 ? "es" : "",
-                               no_query ? " (status not queried)" : "");
-               for_each_string_list(show_remote_info_item, info.list, &info);
+                       printf_ln(Q_("  Remote branch:%s",
+                                    "  Remote branches:%s",
+                                    info.list->nr),
+                                 no_query ? _(" (status not queried)") : "");
+               for_each_string_list(info.list, show_remote_info_item, &info);
                string_list_clear(info.list, 0);
 
                /* git pull info */
                info.width = 0;
                info.any_rebase = 0;
-               for_each_string_list(add_local_to_show_info, &branch_list, &info);
+               for_each_string_list(&branch_list, add_local_to_show_info, &info);
                if (info.list->nr)
-                       printf("  Local branch%s configured for 'git pull':\n",
-                              info.list->nr > 1 ? "es" : "");
-               for_each_string_list(show_local_info_item, info.list, &info);
+                       printf_ln(Q_("  Local branch configured for 'git pull':",
+                                    "  Local branches configured for 'git pull':",
+                                    info.list->nr));
+               for_each_string_list(info.list, show_local_info_item, &info);
                string_list_clear(info.list, 0);
 
                /* git push info */
                if (states.remote->mirror)
-                       printf("  Local refs will be mirrored by 'git push'\n");
+                       printf_ln(_("  Local refs will be mirrored by 'git push'"));
 
                info.width = info.width2 = 0;
-               for_each_string_list(add_push_to_show_info, &states.push, &info);
+               for_each_string_list(&states.push, add_push_to_show_info, &info);
                qsort(info.list->items, info.list->nr,
                        sizeof(*info.list->items), cmp_string_with_push);
                if (info.list->nr)
-                       printf("  Local ref%s configured for 'git push'%s:\n",
-                               info.list->nr > 1 ? "s" : "",
-                               no_query ? " (status not queried)" : "");
-               for_each_string_list(show_push_info_item, info.list, &info);
+                       printf_ln(Q_("  Local ref configured for 'git push'%s:",
+                                    "  Local refs configured for 'git push'%s:",
+                                    info.list->nr),
+                                 no_query ? _(" (status not queried)") : "");
+               for_each_string_list(info.list, show_push_info_item, &info);
                string_list_clear(info.list, 0);
 
                free_remote_ref_states(&states);
@@ -1140,10 +1213,10 @@ static int set_head(int argc, const char **argv)
                memset(&states, 0, sizeof(states));
                get_remote_ref_states(argv[0], &states, GET_HEAD_NAMES);
                if (!states.heads.nr)
-                       result |= error("Cannot determine remote HEAD");
+                       result |= error(_("Cannot determine remote HEAD"));
                else if (states.heads.nr > 1) {
-                       result |= error("Multiple remote HEAD branches. "
-                                       "Please choose one explicitly with:");
+                       result |= error(_("Multiple remote HEAD branches. "
+                                         "Please choose one explicitly with:"));
                        for (i = 0; i < states.heads.nr; i++)
                                fprintf(stderr, "  git remote set-head %s %s\n",
                                        argv[0], states.heads.items[i].string);
@@ -1152,18 +1225,17 @@ static int set_head(int argc, const char **argv)
                free_remote_ref_states(&states);
        } else if (opt_d && !opt_a && argc == 1) {
                if (delete_ref(buf.buf, NULL, REF_NODEREF))
-                       result |= error("Could not delete %s", buf.buf);
+                       result |= error(_("Could not delete %s"), buf.buf);
        } else
                usage_with_options(builtin_remote_sethead_usage, options);
 
        if (head_name) {
-               unsigned char sha1[20];
                strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name);
                /* make sure it's valid */
-               if (!resolve_ref(buf2.buf, sha1, 1, NULL))
-                       result |= error("Not a valid ref: %s", buf2.buf);
+               if (!ref_exists(buf2.buf))
+                       result |= error(_("Not a valid ref: %s"), buf2.buf);
                else if (create_symref(buf.buf, buf2.buf, "remote set-head"))
-                       result |= error("Could not setup %s", buf.buf);
+                       result |= error(_("Could not setup %s"), buf.buf);
                if (opt_a)
                        printf("%s/HEAD set to %s\n", argv[0], head_name);
                free(head_name);
@@ -1178,7 +1250,7 @@ static int prune(int argc, const char **argv)
 {
        int dry_run = 0, result = 0;
        struct option options[] = {
-               OPT__DRY_RUN(&dry_run),
+               OPT__DRY_RUN(&dry_run, "dry run"),
                OPT_END()
        };
 
@@ -1199,18 +1271,18 @@ static int prune_remote(const char *remote, int dry_run)
        int result = 0, i;
        struct ref_states states;
        const char *dangling_msg = dry_run
-               ? " %s will become dangling!\n"
-               : " %s has become dangling!\n";
+               ? _(" %s will become dangling!")
+               : _(" %s has become dangling!");
 
        memset(&states, 0, sizeof(states));
        get_remote_ref_states(remote, &states, GET_REF_STATES);
 
        if (states.stale.nr) {
-               printf("Pruning %s\n", remote);
-               printf("URL: %s\n",
+               printf_ln(_("Pruning %s"), remote);
+               printf_ln(_("URL: %s"),
                       states.remote->url_nr
                       ? states.remote->url[0]
-                      : "(no URL)");
+                      : _("(no URL)"));
        }
 
        for (i = 0; i < states.stale.nr; i++) {
@@ -1219,8 +1291,12 @@ static int prune_remote(const char *remote, int dry_run)
                if (!dry_run)
                        result |= delete_ref(refname, NULL, 0);
 
-               printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
-                      abbrev_ref(refname, "refs/remotes/"));
+               if (dry_run)
+                       printf_ln(_(" * [would prune] %s"),
+                              abbrev_ref(refname, "refs/remotes/"));
+               else
+                       printf_ln(_(" * [pruned] %s"),
+                              abbrev_ref(refname, "refs/remotes/"));
                warn_dangling_symref(stdout, dangling_msg, refname);
        }
 
@@ -1308,7 +1384,7 @@ static int set_remote_branches(const char *remotename, const char **branches,
        strbuf_addf(&key, "remote.%s.fetch", remotename);
 
        if (!remote_is_configured(remotename))
-               die("No such remote '%s'", remotename);
+               die(_("No such remote '%s'"), remotename);
        remote = remote_get(remotename);
 
        if (!add_mode && remove_all_fetch_refspecs(remotename, key.buf)) {
@@ -1335,7 +1411,7 @@ static int set_branches(int argc, const char **argv)
        argc = parse_options(argc, argv, NULL, options,
                             builtin_remote_setbranches_usage, 0);
        if (argc == 0) {
-               error("no remote specified");
+               error(_("no remote specified"));
                usage_with_options(builtin_remote_setbranches_usage, options);
        }
        argv[argc] = NULL;
@@ -1364,11 +1440,11 @@ static int set_url(int argc, const char **argv)
                            "delete URLs"),
                OPT_END()
        };
-       argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
+       argc = parse_options(argc, argv, NULL, options, builtin_remote_seturl_usage,
                             PARSE_OPT_KEEP_ARGV0);
 
        if (add_mode && delete_mode)
-               die("--add --delete doesn't make sense");
+               die(_("--add --delete doesn't make sense"));
 
        if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))
                usage_with_options(builtin_remote_seturl_usage, options);
@@ -1382,7 +1458,7 @@ static int set_url(int argc, const char **argv)
                oldurl = newurl;
 
        if (!remote_is_configured(remotename))
-               die("No such remote '%s'", remotename);
+               die(_("No such remote '%s'"), remotename);
        remote = remote_get(remotename);
 
        if (push_mode) {
@@ -1408,7 +1484,7 @@ static int set_url(int argc, const char **argv)
 
        /* Old URL specified. Demand that one matches. */
        if (regcomp(&old_regex, oldurl, REG_EXTENDED))
-               die("Invalid old URL pattern: %s", oldurl);
+               die(_("Invalid old URL pattern: %s"), oldurl);
 
        for (i = 0; i < urlset_nr; i++)
                if (!regexec(&old_regex, urlset[i], 0, NULL, 0))
@@ -1416,9 +1492,9 @@ static int set_url(int argc, const char **argv)
                else
                        negative_matches++;
        if (!delete_mode && !matches)
-               die("No such URL found: %s", oldurl);
+               die(_("No such URL found: %s"), oldurl);
        if (delete_mode && !negative_matches && !push_mode)
-               die("Will not delete all non-push URLs");
+               die(_("Will not delete all non-push URLs"));
 
        regfree(&old_regex);
 
@@ -1438,10 +1514,10 @@ static int get_one_entry(struct remote *remote, void *priv)
 
        if (remote->url_nr > 0) {
                strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]);
-               string_list_append(remote->name, list)->util =
+               string_list_append(list, remote->name)->util =
                                strbuf_detach(&url_buf, NULL);
        } else
-               string_list_append(remote->name, list)->util = NULL;
+               string_list_append(list, remote->name)->util = NULL;
        if (remote->pushurl_nr) {
                url = remote->pushurl;
                url_nr = remote->pushurl_nr;
@@ -1452,7 +1528,7 @@ static int get_one_entry(struct remote *remote, void *priv)
        for (i = 0; i < url_nr; i++)
        {
                strbuf_addf(&url_buf, "%s (push)", url[i]);
-               string_list_append(remote->name, list)->util =
+               string_list_append(list, remote->name)->util =
                                strbuf_detach(&url_buf, NULL);
        }
 
@@ -1461,7 +1537,7 @@ static int get_one_entry(struct remote *remote, void *priv)
 
 static int show_all(void)
 {
-       struct string_list list = { NULL, 0, 0 };
+       struct string_list list = STRING_LIST_INIT_NODUP;
        int result;
 
        list.strdup_strings = 1;
@@ -1490,7 +1566,7 @@ static int show_all(void)
 int cmd_remote(int argc, const char **argv, const char *prefix)
 {
        struct option options[] = {
-               OPT_BOOLEAN('v', "verbose", &verbose, "be verbose; must be placed before a subcommand"),
+               OPT__VERBOSE(&verbose, "be verbose; must be placed before a subcommand"),
                OPT_END()
        };
        int result;
@@ -1519,7 +1595,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix)
        else if (!strcmp(argv[0], "update"))
                result = update(argc, argv);
        else {
-               error("Unknown subcommand: %s", argv[0]);
+               error(_("Unknown subcommand: %s"), argv[0]);
                usage_with_options(builtin_remote_usage, options);
        }