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>
This commit is contained in:
parent
1822b86a51
commit
b52d00aede
@ -635,7 +635,7 @@ static int mv(int argc, const char **argv)
|
|||||||
old_remote_context = STRBUF_INIT;
|
old_remote_context = STRBUF_INIT;
|
||||||
struct string_list remote_branches = STRING_LIST_INIT_NODUP;
|
struct string_list remote_branches = STRING_LIST_INIT_NODUP;
|
||||||
struct rename_info rename;
|
struct rename_info rename;
|
||||||
int i;
|
int i, refspec_updated = 0;
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage_with_options(builtin_remote_rename_usage, options);
|
usage_with_options(builtin_remote_rename_usage, options);
|
||||||
@ -677,12 +677,13 @@ static int mv(int argc, const char **argv)
|
|||||||
strbuf_reset(&buf2);
|
strbuf_reset(&buf2);
|
||||||
strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
|
strbuf_addstr(&buf2, oldremote->fetch_refspec[i]);
|
||||||
ptr = strstr(buf2.buf, old_remote_context.buf);
|
ptr = strstr(buf2.buf, old_remote_context.buf);
|
||||||
if (ptr)
|
if (ptr) {
|
||||||
|
refspec_updated = 1;
|
||||||
strbuf_splice(&buf2,
|
strbuf_splice(&buf2,
|
||||||
ptr-buf2.buf + strlen(":refs/remotes/"),
|
ptr-buf2.buf + strlen(":refs/remotes/"),
|
||||||
strlen(rename.old), rename.new,
|
strlen(rename.old), rename.new,
|
||||||
strlen(rename.new));
|
strlen(rename.new));
|
||||||
else
|
} else
|
||||||
warning("Not updating non-default fetch respec\n"
|
warning("Not updating non-default fetch respec\n"
|
||||||
"\t%s\n"
|
"\t%s\n"
|
||||||
"\tPlease update the configuration manually if necessary.",
|
"\tPlease update the configuration manually if necessary.",
|
||||||
@ -705,6 +706,9 @@ static int mv(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!refspec_updated)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First remove symrefs, then rename the rest, finally create
|
* First remove symrefs, then rename the rest, finally create
|
||||||
* the new symrefs.
|
* the new symrefs.
|
||||||
|
@ -637,7 +637,8 @@ test_expect_success 'rename does not update a non-default fetch refspec' '
|
|||||||
(cd four.one &&
|
(cd four.one &&
|
||||||
git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
|
git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
|
||||||
git remote rename origin upstream &&
|
git remote rename origin upstream &&
|
||||||
test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*")
|
test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
|
||||||
|
git rev-parse -q origin/master)
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user