remote: only update remote-tracking branch if updating refspec

'git remote rename' will only update the remote's fetch refspec if it looks like a default one. If the remote has no default fetch refspec, as in [remote "origin"] url = git://git.kernel.org/pub/scm/git/git.git fetch = +refs/heads/*:refs/remotes/upstream/* we would not update the fetch refspec and even if there is a ref called "refs/remotes/origin/master", we should not rename it, since it was not created by fetching from the remote. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Sep 10, 2011 at 15:39 UTC b52d00aedeb94f12a16afcef1bb33c989f9b4105
2 files changed +9 -4
builtin/remote.c
+7 -3
@@ -635,7 +635,7 @@ static int mv(int argc, const char **argv)
635 old_remote_context = STRBUF_INIT;
636 struct string_list remote_branches = STRING_LIST_INIT_NODUP;
637 struct rename_info rename;
638 - int i;
638 + int i, refspec_updated = 0;
639
640 if (argc != 3)
641 usage_with_options(builtin_remote_rename_usage, options);
@@ -677,12 +677,13 @@ static int mv(int argc, const char **argv)
677 strbuf_reset(&buf2);
678 strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
679 ptr = strstr(buf2.buf, old_remote_context.buf);
680 - if (ptr)
680 + if (ptr) {
681 + refspec_updated = 1;
682 strbuf_splice(&buf2,
683 ptr-buf2.buf + strlen(":refs/remotes/"),
684 strlen(rename.old), rename.new,
685 strlen(rename.new));
685 - else
686 + } else
687 warning("Not updating non-default fetch respec\n"
688 "\t%s\n"
689 "\tPlease update the configuration manually if necessary.",
@@ -705,6 +706,9 @@ static int mv(int argc, const char **argv)
706 }
707 }
708
709 + if (!refspec_updated)
710 + return 0;
711 +
712 /*
713 * First remove symrefs, then rename the rest, finally create
714 * the new symrefs.
t/t5505-remote.sh
+2 -1
@@ -637,7 +637,8 @@ test_expect_success 'rename does not update a non-default fetch refspec' '
637 (cd four.one &&
638 git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
639 git remote rename origin upstream &&
640 - test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*")
640 + test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
641 + git rev-parse -q origin/master)
642
643 '
644