remote: "rename o foo" should not rename ref "origin/bar"
When renaming a remote called 'o' using 'git remote rename o foo', git should also rename any remote-tracking branches for the remote. This does happen, but any remote-tracking branches starting with 'refs/remotes/o', such as 'refs/remotes/origin/bar', will also be renamed (to 'refs/remotes/foorigin/bar' in this case). Fix it by simply matching one more character, up to the slash following the remote name. 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 1, 2011 at 20:50 UTC
60e5eee0f1a70e09f28d1e55b3aaddb59eeea887
2 files changed
+11
-1
builtin/remote.c
+1
-1
@@ -580,7 +580,7 @@ static int read_remote_branches(const char *refname,
580
unsigned char orig_sha1[20];
581
const char *symref;
582
583
- strbuf_addf(&buf, "refs/remotes/%s", rename->old);
583
+ strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
584
if (!prefixcmp(refname, buf.buf)) {
585
item = string_list_append(rename->remote_branches, xstrdup(refname));
586
symref = resolve_ref(refname, orig_sha1, 1, &flag);
t/t5505-remote.sh
+10
@@ -651,6 +651,16 @@ test_expect_success 'rename a remote with name part of fetch spec' '
651
652
'
653
654
+test_expect_success 'rename a remote with name prefix of other remote' '
655
+
656
+ git clone one four.three &&
657
+ (cd four.three &&
658
+ git remote add o git://example.com/repo.git &&
659
+ git remote rename o upstream &&
660
+ test "$(git rev-parse origin/master)" = "$(git rev-parse master)")
661
+
662
+'
663
+
664
cat > remotes_origin << EOF
665
URL: $(pwd)/one
666
Push: refs/heads/master:refs/heads/upstream