Skip to content

Commit b52d00a

Browse files
Martin von Zweigbergkgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1822b86 commit b52d00a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

builtin/remote.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ static int mv(int argc, const char **argv)
635635
old_remote_context = STRBUF_INIT;
636636
struct string_list remote_branches = STRING_LIST_INIT_NODUP;
637637
struct rename_info rename;
638-
int i;
638+
int i, refspec_updated = 0;
639639

640640
if (argc != 3)
641641
usage_with_options(builtin_remote_rename_usage, options);
@@ -677,12 +677,13 @@ static int mv(int argc, const char **argv)
677677
strbuf_reset(&buf2);
678678
strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
679679
ptr = strstr(buf2.buf, old_remote_context.buf);
680-
if (ptr)
680+
if (ptr) {
681+
refspec_updated = 1;
681682
strbuf_splice(&buf2,
682683
ptr-buf2.buf + strlen(":refs/remotes/"),
683684
strlen(rename.old), rename.new,
684685
strlen(rename.new));
685-
else
686+
} else
686687
warning("Not updating non-default fetch respec\n"
687688
"\t%s\n"
688689
"\tPlease update the configuration manually if necessary.",
@@ -705,6 +706,9 @@ static int mv(int argc, const char **argv)
705706
}
706707
}
707708

709+
if (!refspec_updated)
710+
return 0;
711+
708712
/*
709713
* First remove symrefs, then rename the rest, finally create
710714
* the new symrefs.

t/t5505-remote.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,8 @@ test_expect_success 'rename does not update a non-default fetch refspec' '
637637
(cd four.one &&
638638
git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
639639
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)
641642
642643
'
643644

0 commit comments

Comments
 (0)