Merge branch 'mz/remote-rename'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)
* mz/remote-rename:
remote: only update remote-tracking branch if updating refspec
remote rename: warn when refspec was not updated
remote: "rename o foo" should not rename ref "origin/bar"
remote: write correct fetch spec when renaming remote 'remote'

1  2 
builtin/remote.c
diff --combined builtin/remote.c
index f2a9c26dc3494c0881ca3f91b44785c4b52caae7,9c746af460dd9490358d516a381546c5a14571ff..b25dfb44227c42a5d8dadb72c04e5aa694d2ace2
@@@ -88,6 -88,16 +88,6 @@@ static inline int postfixcmp(const cha
        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(list, arg);
 -      return 0;
 -}
 -
  static int fetch_remote(const char *name)
  {
        const char *argv[] = { "fetch", name, NULL, NULL };
@@@ -166,8 -176,8 +166,8 @@@ static int add(int argc, const char **a
                            TAGS_SET),
                OPT_SET_INT(0, NULL, &fetch_tags,
                            "or do not fetch any tag at all (--no-tags)", TAGS_UNSET),
 -              OPT_CALLBACK('t', "track", &track, "branch",
 -                      "branch(es) to track", opt_parse_track),
 +              OPT_STRING_LIST('t', "track", &track, "branch",
 +                              "branch(es) to track"),
                OPT_STRING('m', "master", &master, "branch", "master branch"),
                { OPTION_CALLBACK, 0, "mirror", &mirror, "push|fetch",
                        "set up remote as a mirror to push to or fetch from",
@@@ -570,7 -580,7 +570,7 @@@ static int read_remote_branches(const c
        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(rename->remote_branches, xstrdup(refname));
                symref = resolve_ref(refname, orig_sha1, 1, &flag);
@@@ -621,10 -631,11 +621,11 @@@ static int mv(int argc, const char **ar
                OPT_END()
        };
        struct remote *oldremote, *newremote;
-       struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
+       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);
        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);
+       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 respec\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);
        }
                }
        }
  
+       if (!refspec_updated)
+               return 0;
        /*
         * First remove symrefs, then rename the rest, finally create
         * the new symrefs.