Skip to content

Commit 60e5eee

Browse files
Martin von Zweigbergkgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28f555f commit 60e5eee

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static int read_remote_branches(const char *refname,
580580
unsigned char orig_sha1[20];
581581
const char *symref;
582582

583-
strbuf_addf(&buf, "refs/remotes/%s", rename->old);
583+
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
584584
if (!prefixcmp(refname, buf.buf)) {
585585
item = string_list_append(rename->remote_branches, xstrdup(refname));
586586
symref = resolve_ref(refname, orig_sha1, 1, &flag);

t/t5505-remote.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,16 @@ test_expect_success 'rename a remote with name part of fetch spec' '
651651
652652
'
653653

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+
654664
cat > remotes_origin << EOF
655665
URL: $(pwd)/one
656666
Push: refs/heads/master:refs/heads/upstream

0 commit comments

Comments
 (0)