Merge branch 'jk/remote-rename-without-fetch-refspec' into maint-2.38
"git remote rename" failed to rename a remote without fetch refspec, which has been corrected. * jk/remote-rename-without-fetch-refspec: remote: handle rename of remote without fetch refspec
This commit is contained in:
commit
665d7e08b4
@ -733,29 +733,31 @@ static int mv(int argc, const char **argv, const char *prefix)
|
|||||||
return error(_("Could not rename config section '%s' to '%s'"),
|
return error(_("Could not rename config section '%s' to '%s'"),
|
||||||
buf.buf, buf2.buf);
|
buf.buf, buf2.buf);
|
||||||
|
|
||||||
strbuf_reset(&buf);
|
if (oldremote->fetch.raw_nr) {
|
||||||
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
|
strbuf_reset(&buf);
|
||||||
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
|
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
|
||||||
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
|
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
|
||||||
for (i = 0; i < oldremote->fetch.raw_nr; i++) {
|
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
|
||||||
char *ptr;
|
for (i = 0; i < oldremote->fetch.raw_nr; i++) {
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
strbuf_reset(&buf2);
|
strbuf_reset(&buf2);
|
||||||
strbuf_addstr(&buf2, oldremote->fetch.raw[i]);
|
strbuf_addstr(&buf2, oldremote->fetch.raw[i]);
|
||||||
ptr = strstr(buf2.buf, old_remote_context.buf);
|
ptr = strstr(buf2.buf, old_remote_context.buf);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
refspec_updated = 1;
|
refspec_updated = 1;
|
||||||
strbuf_splice(&buf2,
|
strbuf_splice(&buf2,
|
||||||
ptr-buf2.buf + strlen(":refs/remotes/"),
|
ptr-buf2.buf + strlen(":refs/remotes/"),
|
||||||
strlen(rename.old_name), rename.new_name,
|
strlen(rename.old_name), rename.new_name,
|
||||||
strlen(rename.new_name));
|
strlen(rename.new_name));
|
||||||
} else
|
} else
|
||||||
warning(_("Not updating non-default fetch refspec\n"
|
warning(_("Not updating non-default fetch refspec\n"
|
||||||
"\t%s\n"
|
"\t%s\n"
|
||||||
"\tPlease update the configuration manually if necessary."),
|
"\tPlease update the configuration manually if necessary."),
|
||||||
buf2.buf);
|
buf2.buf);
|
||||||
|
|
||||||
git_config_set_multivar(buf.buf, buf2.buf, "^$", 0);
|
git_config_set_multivar(buf.buf, buf2.buf, "^$", 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
read_branches();
|
read_branches();
|
||||||
|
@ -902,6 +902,17 @@ test_expect_success 'rename a remote renames repo remote.pushDefault but keeps g
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'rename handles remote without fetch refspec' '
|
||||||
|
git clone --bare one no-refspec.git &&
|
||||||
|
# confirm assumption that bare clone does not create refspec
|
||||||
|
test_expect_code 5 \
|
||||||
|
git -C no-refspec.git config --unset-all remote.origin.fetch &&
|
||||||
|
git -C no-refspec.git config remote.origin.url >expect &&
|
||||||
|
git -C no-refspec.git remote rename origin foo &&
|
||||||
|
git -C no-refspec.git config remote.foo.url >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'rename does not update a non-default fetch refspec' '
|
test_expect_success 'rename does not update a non-default fetch refspec' '
|
||||||
git clone one four.one &&
|
git clone one four.one &&
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user