From 28f555f6357ee0706847aff5b476b31b472b325c Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 1 Sep 2011 20:50:33 -0400 Subject: remote: write correct fetch spec when renaming remote 'remote' When renaming a remote whose name is contained in a configured fetch refspec for that remote, we currently replace the first occurrence of the remote name in the refspec. This is correct in most cases, but breaks if the remote name occurs in the fetch refspec before the expected place. For example, we currently change [remote "remote"] url = git://git.kernel.org/pub/scm/git/git.git fetch = +refs/heads/*:refs/remotes/remote/* into [remote "origin"] url = git://git.kernel.org/pub/scm/git/git.git fetch = +refs/heads/*:refs/origins/remote/* Reduce the risk of changing incorrect sections of the refspec by matching the entire ":refs/remotes//" instead of just "". Signed-off-by: Martin von Zweigbergk Signed-off-by: Junio C Hamano --- t/t5505-remote.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 't/t5505-remote.sh') diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 0d0222ea2a..36c807c608 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -631,6 +631,26 @@ test_expect_success 'rename a remote' ' ' +test_expect_success 'rename does not update a non-default fetch refspec' ' + + git clone one four.one && + (cd four.one && + git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* && + git remote rename origin upstream && + test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*") + +' + +test_expect_success 'rename a remote with name part of fetch spec' ' + + git clone one four.two && + (cd four.two && + git remote rename origin remote && + git remote rename remote upstream && + test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*") + +' + cat > remotes_origin << EOF URL: $(pwd)/one Push: refs/heads/master:refs/heads/upstream -- cgit v1.2.1 From 60e5eee0f1a70e09f28d1e55b3aaddb59eeea887 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 1 Sep 2011 20:50:34 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- t/t5505-remote.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't/t5505-remote.sh') diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 36c807c608..15186c8cbf 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -651,6 +651,16 @@ test_expect_success 'rename a remote with name part of fetch spec' ' ' +test_expect_success 'rename a remote with name prefix of other remote' ' + + git clone one four.three && + (cd four.three && + git remote add o git://example.com/repo.git && + git remote rename o upstream && + test "$(git rev-parse origin/master)" = "$(git rev-parse master)") + +' + cat > remotes_origin << EOF URL: $(pwd)/one Push: refs/heads/master:refs/heads/upstream -- cgit v1.2.1 From b52d00aedeb94f12a16afcef1bb33c989f9b4105 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 10 Sep 2011 15:39:23 -0400 Subject: 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 Signed-off-by: Martin von Zweigbergk Signed-off-by: Junio C Hamano --- t/t5505-remote.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 't/t5505-remote.sh') diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 15186c8cbf..e8af615e6d 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -637,7 +637,8 @@ test_expect_success 'rename does not update a non-default fetch refspec' ' (cd four.one && git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* && 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) ' -- cgit v1.2.1